Friday, September 27, 2013

SQL Server date formatting from string

We’ve recently migrated our database to a different server & since this I think the date format querying has changed somehow.

Previously we could use the following..

SELECT * FROM table WHERE date > 'YYYY-MM-DD'

However now we have to use..

SELECT * FROM table WHERE date > 'YYYY-DD-MM'

Can someone tell me what I need to alter to obtain back to the previous version?

Try this one –

Query:

SET DATEFORMAT ymd

Read current settings:

DBCC USEROPTIONS

Output:

Set Option                 Value-------------------------- -----------------...language                   us_englishdateformat                 ymd...

Get image code from url with Javascript

I\’m creating image uploader for my website. I figured out how to upload image from computer & wrote the whole processing script; Now I need to add an option to upload an image from web. My script works fine after the image is converted into 64 bit format:

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAMCAgIC

Looks like it is impossible to do anything helpful with image before it is on my server, so I have this script which creates a temporary copy of the image on my host:

$content = file_get_contents(\"http://cs6045.vk.me/v6045344/43ce/D7BD4GsCmG4.jpg\");file_put_contents(\"image.png\",$content);

So, what I need to do is to take a link \”image.png\” in JavaScript & transform it to 64 bit format to apply further actions in JavaScript. I can\’t find a solution anywhere, can someone help?

Please take a look at this thread, where a complete solution to convert an image to base64 is provided. This requires HTML5 tho, so your client needs a relatively up-to-date browser.

There seems tho to be some issues between the browsers, since they process image data differentely. If you want 100% the same Base64 encoding as your PHP-script, I suggest you simply make an AJAX-call to the script, which processes the image. Then it returns the Base64 string.

javascript regex validate years in range

I have input field for year & I need a regex for validation it.
I have such code: ^([12]d)?(dd)$.
But I want allow to validate only years in certain range (1990-2010, for example). How can I do it?

Edit. range must be 1950-2050

Try this:

1990 – 2010:

/^(199d|200d|2010)$/

1950 – 2050:

/^(19[5-9]d|20[0-4]d|2050)$/

Other examples:

1945 – 2013:

/^(194[5-9]|19[5-9]d|200d|201[0-3])$/

1812 – 3048:

/^(181[2-9]|18[2-9]d|19dd|2d{3}|30[0-3]d|304[0-8])$/

Basically, you need to split your range into effortless “regexable” chunks:

1812-3048: 1812-1819 + 1820-1899 + 1900-1999 + 2000-2999 + 3000-3039 + 3040-3048    regex: 181[2-9]    18[2-9]d   19dd      2d{3}      30[0-3]d   304[0-8]

Update method in Python dictionary

I was trying to update values in my dictionary, I came across 2 ways to do so:

product.update(map(key, value))product.update(key, value)

What is the difference between them?

The difference is that the second method does not work:

>>> {}.update(1, 2)Traceback (most recent call last):  File "<stdin>", line 1, in <module>TypeError: update expected at most 1 arguments, received 2

dict.update() expects to find a iterable of key-value pairs, keyword arguments, or another dictionary:

Update the dictionary with the key/value pairs from other, overwriting existing keys. Return None.

update() accepts either another dictionary object or an iterable of key/value pairs (as tuples or other iterables of length two). If keyword arguments are specified, the dictionary is then updated with those key/value pairs: d.update(red=1, blue=2).

map() is a built-in method that produces a sequence by applying the elements of the second (and subsequent) arguments to the first argument, which must be a callable. Unless your key object is a callable & the value object is a sequence, your first method will fail too.

Demo of a working map() application:

>>> def key(v):...     return (v, v)... >>> value = range(3)>>> map(key, value)[(0, 0), (1, 1), (2, 2)]>>> product = {}>>> product.update(map(key, value))>>> product{0: 0, 1: 1, 2: 2}

Here map() just produces key-value pairs, which satisfies the dict.update() expectations.

Use Aggregate Function in UNION ALL result set

How can I use aggregate Functions in UNION ALL Resultset

FOR EXAMPLE

SELECT A,B FROM MyTableUNION ALLSELECT B,C FROM MYAnotherTable

Result Set Would Be

    A  B--------------    1  2    3  4    4  5    6  7

When I tried to obtain MAX(A) it returns 3. I want 6.

When I tried to obtain MAX(B) it returns 4. I want 7.

Other than Max(), Can I obtain another aggregate function which user defined?

For example:

(SELECT TOP 1 A WHERE B=5)

Try this way:

select max(A)from(      SELECT A,B FROM MyTable      UNION ALL      SELECT B,C FROM MYAnotherTable    ) Tab

If the column A is varchar (You said that in the comment below) try this way:

select max(A)from(      SELECT cast(A as int) as A,B FROM MyTable      UNION ALL      SELECT B,C FROM MYAnotherTable    ) Tab

With TOP 1

select max(A)from(      SELECT top 1 cast(A as int) as A,B FROM MyTable      UNION ALL      SELECT B,C FROM MYAnotherTable    ) Tab

Adding char to string in C++

I work with Eclipse & Arduino.

I want to add a char to a string. I tried to use append,insert ( yet these can not be resolved)
I tried to use += yet when i print the string it always have one char.Basically i deletes the string & writes only the new char i want to add in.
I tried moreover concat & it does the same thing.Also strcat gives me headache with the operands cause it needs a const char pointer & i want to add a char that changes.

while (theSettings.available()) {character = theSettings.read();if(character == '/')         {    // Comment - ignore this line    while(character != '\n'){        character = theSettings.read();    }} else if(isalnum(character)){  // Add a character to the description    Serial.println(character);    description +=character;    //description.concat(character);    Serial.println(description);}

It sounds like what you want (for convenience) is the String object class available with the Arduino library.
http://arduino.cc/en/Reference/StringObject

Thursday, September 26, 2013

WordPress mobile theme: WPTouch

Download: http://prefiles.com/x9lxgihalqsy/BraveNewCode.WPTouch.Pro.v3.0.8.for.WordPress.rar

Remember: this is a PLUGIN, not a theme.
Install: put extracted wptouch-pro-3 folder under plugins folder.