Skip to content

Instantly share code, notes, and snippets.

Avatar

I-am Konstantin scriptonian

View GitHub Profile
View scilla-structure.js
(***************************************************)
(* scilla version *)
(***************************************************)
scilla_version 1
(***************************************************)
(* associated library *)
(***************************************************)
@scriptonian
scriptonian / cloudSettings
Created Jun 25, 2020
Visual Studio Code Settings Sync Gist
@scriptonian
scriptonian / compress
Created Aug 2, 2018
Mac compress multiples files with command line
View compress
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 — forked from alikrc/ajaxBearer.js
ajax post with bearer token
View ajaxBearer.js
$.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 Apr 8, 2018
knapsack using greedy algorithms approach
View knapsack-greedy.js
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 Apr 1, 2018
Greedy Algorithms - Minimum Coin Change Problem
View min-coin-change.js
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 Mar 21, 2018
Maximum Sum Contiguous Subarray Problem - Javascript
View maxsubarray.js
/*
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 Mar 20, 2018
Longest common substring
View lcs.js
/*
* 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 Mar 17, 2018
Longest Common Subsequence
View lcs.js
/*
* 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 Mar 16, 2018
0 - 1 knapsack javascript
View knapsack.js
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);