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 / test_node.ts
Created March 8, 2019 01:32
implementation of a prefix tree
var mother_node = new node(null, null);
var string_to_store = "rupsa";
var previous_node = mother_node;
var stored_nodes = [];
string_to_store.split('').forEach(function (element, index) {
var newNode = new node(element, previous_node);
stored_nodes.push(newNode);
previous_node = newNode;
})
console.log(stored_nodes);
@Trshant
Trshant / test_node.ts
Created March 8, 2019 01:31
implementation of a prefix tree
var mother_node = new node(null, null);
var string_to_store = "rupsa";
var previous_node = mother_node;
var stored_nodes = [];
string_to_store.split('').forEach(function (element, index) {
var newNode = new node(element, previous_node);
stored_nodes.push(newNode);
previous_node = newNode;
})
console.log(stored_nodes);
@Trshant
Trshant / radio.sh
Created January 28, 2019 05:01
this is a sh script where i can play some internet radio
#!/bin/bash
# call this using bash radio.sh Mirchi
# Start list of radio. If the link ends with m3u, then add it as pWhateverYoucallIt. else put it in as cName
pMajesticJukebox="http://uk3.internet-radio.com:8405/live.m3u"
cMirchi='http://peridot.streamguys.com:7150/Mirchi'
cBollywoodHits='http://50.7.77.115:8174/'
cAfsanaIndia='http://174.36.206.197:7019/stream/1/'
#end list of Radio Stations
@Trshant
Trshant / dynamic_naive.js
Created January 25, 2019 04:20
I have been trying to get some kind of intiution in these kind of [problems](https://medium.com/@codingfreak/top-50-dynamic-programming-practice-problems-4208fed71aa3), while i can get the naive solutions done on my own, i cannot think up the solutions easily to the point where i can match the solutions given to these questions in each of those …
function catu(one, two) {
var returnu = [];
two.forEach(element => {
returnu.push(one + element);
returnu.push(element);
});
return returnu;
}
function main_fun(stringu) {
if (stringu.length == 1) {
<?php
foreach($_POST['outcome'] as $okey=>$oval){
$rs = mysql_query("INSERT INTO form_quest_outcome_fqo (qid_fqo, idotc_fqo) VALUES ('{$q_id}','{$oval}')", $mx_shop);
$idfqo = mysql_insert_id();
foreach($_POST['outcome_inctype'][$oval] as $ikey=>$ival){
mysql_query("INSERT INTO form_quest_outcomeit_fqi (idfqo_fqi, qid_fqi, idit_fqi) VALUES ('{$idfqo}','{$q_id}','{$ival}')", $mx_shop);
}
}
?>
@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
@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 / 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
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 / 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();