Skip to content

Instantly share code, notes, and snippets.

View Trshant's full-sized avatar
🤠
docker/kubernetes/

Trshant Trshant

🤠
docker/kubernetes/
View GitHub Profile
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)];
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
@Trshant
Trshant / create trigram
Created April 22, 2017 05:25
bits of markov.js
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)];
@Trshant
Trshant / readability-bookmarklet.js
Created March 7, 2017 00:30 — forked from darkhelmet/readability-bookmarklet.js
Original readability bookmarklet
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
@Trshant
Trshant / Combinations.js
Last active December 2, 2016 03:40
Getting combinations from an array
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);
}
@Trshant
Trshant / RoundingToNextTop.php
Last active September 9, 2016 12:01
This gives the number rounded off the next biggest integer. Please see beneath the definition to see what i mean
<?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 ) ;
@Trshant
Trshant / ipak.R
Created September 8, 2016 13:24 — forked from stevenworthington/ipak.R
Install and load multiple R packages at once
# 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)
}
string <- "Hello World"
string
@Trshant
Trshant / print js
Created March 22, 2016 08:30
Detecting Print Requests with JavaScript
(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');
@Trshant
Trshant / getLatLng.js
Created September 2, 2015 13:55
To get the latitude and longitude of the place by using the browser
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
console.log( latitude , longitude );
})