Skip to content

Instantly share code, notes, and snippets.

View scriptonian's full-sized avatar

I-am Konstantin scriptonian

View GitHub Profile
(***************************************************)
(* scilla version *)
(***************************************************)
scilla_version 1
(***************************************************)
(* associated library *)
(***************************************************)
@scriptonian
scriptonian / cloudSettings
Created June 25, 2020 14:24
Visual Studio Code Settings Sync Gist
// Empty
@scriptonian
scriptonian / compress
Created August 2, 2018 18:16
Mac compress multiples files with command line
zip -9 -r archive.zip ./node_modules index.js (will compress everything in node modules folder as well as index.js) into a file called archive.zip
@scriptonian
scriptonian / ajaxBearer.js
Created May 11, 2018 17:41 — forked from alikrc/ajaxBearer.js
ajax post with bearer token
$.ajax({
url: "http://localhost:33460/api/Account/userinfo",
dataType: 'json',
data: {
foo: 'bar'
},
success: function(data, status) {
return console.log("The returned data", data);
},
beforeSend: function(xhr, settings) { xhr.setRequestHeader('Authorization','Bearer ' + tokenString ); } //set tokenString before send
@scriptonian
scriptonian / knapsack-greedy.js
Created April 8, 2018 13:46
knapsack using greedy algorithms approach
function greedyKnapsack(weights, values, totalItems, capacity) {
//set some default values
var curKnapsackWeight = 0,
sackValue = 0;
//iterate through the collection
for(var i = 0; i < totalItems && curKnapsackWeight <= capacity; i++) {
/*
if the current weight is less than or equal to what we can
add to the knapsack, then we add it. else it will be too
@scriptonian
scriptonian / min-coin-change.js
Created April 1, 2018 15:54
Greedy Algorithms - Minimum Coin Change Problem
function MinimumCoinChange(cointypes) {
//save the coin types in coins
this.coins = cointypes;
this.numCoinTypes = this.coins.length;
}
MinimumCoinChange.prototype = {
/*
pass cent amount to this function
*/
@scriptonian
scriptonian / maxsubarray.js
Created March 21, 2018 23:23
Maximum Sum Contiguous Subarray Problem - Javascript
/*
O(n^3) solution
*/
function maxSubarraySum(arr) {
//store the length of array
var aLen = arr.length,
//set the current max sum to zero
maximumSum = 0;
//Outter Loop
for(var i = 0; i < aLen; i++) {
@scriptonian
scriptonian / lcs.js
Created March 20, 2018 02:48
Longest common substring
/*
* USING DYNAMIC PROGRAMMING:
*/
/*
ARRAY HELPER FUNCTION
Array extension by Douglas Crockford Javascript The Good Parts (O’Reilly, p. 64).
This helps you create a multi dimensional array of size ROW & COLS and allows you
to initialize the array with values
@scriptonian
scriptonian / lcs.js
Created March 17, 2018 21:24
Longest Common Subsequence
/*
* USING RECURSION
*/
function LCS(S1, m, S2, n) {
var finalResult;
//define base case. if the length of either strings are zero,
//then no need to continue return 0
if(m === 0 || n === 0) {
finalResult = 0;
@scriptonian
scriptonian / knapsack.js
Last active March 16, 2018 03:40
0 - 1 knapsack javascript
function knapsack(itemsNumber, capacity, weights, values) {
var finalResult;
if(itemsNumber === 0 || capacity === 0) {
finalResult = 0;
} else if(weights[itemsNumber] > capacity) {
finalResult = knapsack(itemsNumber - 1, capacity, weights, values);
} else {
var dontPutInKnapsack = knapsack(itemsNumber - 1, capacity, weights, values);