Skip to content

Instantly share code, notes, and snippets.

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

Trshant Trshant

🤠
docker/kubernetes/
View GitHub Profile
@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 / 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 / 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)];
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
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 / SAVE_CSV.js
Created April 27, 2017 13:13
saves a CSV with a specific name
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();
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
@Trshant
Trshant / SuperSimple.SQL
Created September 3, 2017 01:12
Simple SQL to get a list of numbers
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
@Trshant
Trshant / spiral.rb
Created January 27, 2018 03:33
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
=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.
@Trshant
Trshant / minimumAbsoluteDifference.rb
Last active January 30, 2018 00:35
### [Challenge Name: Minimum Absolute Difference in an Array](/challenges/minimum-absolute-difference-in-an-array) Consider an array of integers, $A = a_0, a_1, \ldots, a_{n-1}$. We define the [absolute difference](https://en.wikipedia.org/wiki/Absolute_difference) between two elements, $a_i$ and $a_j$ (where $i \ne j$), to be the [absolute value](
#!/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