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
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 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
<?php | |
function RoundingToNextTop( $num , $rounding ) { | |
return ( round( $num , (-1 * $rounding ) ) < $num )? round( $num , (-1 * $rounding ))+pow ( 10 , $rounding ) : round( $num , (-1 * $rounding ) ) ; | |
} | |
echo RoundingToNextTop( 13.3583 , 1 ) ; | |
// 20 | |
echo RoundingToNextTop( 103.3583 , 1 ) ; | |
// 110 | |
echo RoundingToNextTop( 103.3583 , 2 ) ; |
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
# ipak function: install and load multiple R packages. | |
# check to see if packages are installed. Install them if they are not, then load them into the R session. | |
ipak <- function(pkg){ | |
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])] | |
if (length(new.pkg)) | |
install.packages(new.pkg, dependencies = TRUE) | |
sapply(pkg, require, character.only = TRUE) | |
} |
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
string <- "Hello World" | |
string |
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() { | |
var beforePrint = function() { | |
console.log('Functionality to run before printing.'); | |
}; | |
var afterPrint = function() { | |
console.log('Functionality to run after printing'); | |
}; | |
if (window.matchMedia) { | |
var mediaQueryList = window.matchMedia('print'); |
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
navigator.geolocation.getCurrentPosition(function(position) { | |
var latitude = position.coords.latitude; | |
var longitude = position.coords.longitude; | |
console.log( latitude , longitude ); | |
}) |