This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function combinations(str) { | |
var fn = function(active, rest, a) { | |
if (!active && !rest) | |
return; | |
if (!rest) { | |
a.push(active); | |
} else { | |
fn(active + rest[0], rest.slice(1), a); | |
fn(active, rest.slice(1), a); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){readConvertLinksToFootnotes=false;readStyle='style-newspaper';readSize='size-medium';readMargin='margin-wide';_readability_script=document.createElement('script');_readability_script.type='text/javascript';_readability_script.src='http://lab.arc90.com/experiments/readability/js/readability.js?x='+(Math.random());document.documentElement.appendChild(_readability_script);_readability_css=document.createElement('link');_readability_css.rel='stylesheet';_readability_css.href='http://lab.arc90.com/experiments/readability/css/readability.css';_readability_css.type='text/css';_readability_css.media='all';document.documentElement.appendChild(_readability_css);_readability_print_css=document.createElement('link');_readability_print_css.rel='stylesheet';_readability_print_css.href='http://lab.arc90.com/experiments/readability/css/readability-print.css';_readability_print_css.media='print';_readability_print_css.type='text/css';document.getElementsByTagName('head')[0].appendChild(_readability_prin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function create(trigram_dict ){ | |
new_string_arr = ["Yo","mama"]; | |
prevword=trigram_dict [ new_string_arr[new_string_arr.length-2]; | |
pprevword=new_string_arr[new_string_arr.length-1] ; | |
while( typeof( trigram_dict [prevword+' '+pprevword] ) != "undefined" ){ | |
candidate_words = trigram_dict [ prevword+' '+pprevword ] ; | |
//select word randomly out of all candidates | |
item = candidate_words[Math.floor( | |
Math.random() * candidate_words.length)]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigram_dict = {}; | |
str_arr.forEach( function(e,i){ | |
sent = e; | |
word_tokens = str.split(" "); | |
word_tokens.forEach( | |
function(e,i){ | |
if( i < 1 ){ return true; } | |
if( i == ( word_tokens.length - 1 ) ){ return true; } | |
// check if key (previous-word current-word) present |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function create(trigram_dict ){ | |
new_string_arr = ["Yo","mama"]; | |
prevword=trigram_dict [ new_string_arr[new_string_arr.length-2]; | |
pprevword=new_string_arr[new_string_arr.length-1] ; | |
while( typeof( trigram_dict [prevword+' '+pprevword] ) != "undefined" ){ | |
candidate_words = trigram_dict [ prevword+' '+pprevword ] ; | |
//select word randomly out of all candidates | |
item = candidate_words[Math.floor( | |
Math.random() * candidate_words.length)]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ajax_download(url, data, input_name) { | |
console.log( url, data, encodeURI( JSON.stringify(data) ) , input_name ); | |
var form = $('<form method="POST" action="' + url + '">'); | |
$.each(data, function(k, v) { | |
form.append($('<input type="hidden" name="' + k + | |
'" value="' + encodeURI( v ) + '">')); | |
}); | |
$('body').append(form); | |
form.submit(); | |
form.remove(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * FROM (select * from | |
(select adddate('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) selected_date from | |
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0, | |
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1, | |
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2, | |
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3, | |
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v | |
where selected_date between '2012-01-1' and '2012-05-15')x WHERE DATE_FORMAT( x.selected_date , '%w' ) = 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT 1 as 'a' | |
UNION SELECT 2 | |
UNION SELECT 3 | |
UNION SELECT 4 | |
UNION SELECT 5 | |
UNION SELECT 6 | |
UNION SELECT 7 | |
UNION SELECT 8 | |
UNION SELECT 9 | |
UNION SELECT 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
This file will show many many ways of writing comments, | |
but it is mainly a demonstration of | |
making an array of numbers print in a spiral way using ruby language. | |
Have a look at the above representation of the array. | |
This is how the numbers should print spirally. | |
The first array is of the size 3X3. The second is 5X5. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ruby | |
def minimumAbsoluteDifference(n, arr) | |
b = arr.sort! | |
c = b.map.with_index {|a,i| a - (b[i+1]||0) } | |
d = c.map( &:abs ) | |
return d.sort[0] | |
end | |
n = gets.strip.to_i |