Skip to content

Instantly share code, notes, and snippets.

View railsstudent's full-sized avatar
🏠
Researching third-party library

Connie Leung railsstudent

🏠
Researching third-party library
View GitHub Profile
function stripUrlParams(url, paramsToStrip){
let [urlPath, urlParams] = url.split('?');
let paramKVMap = {};
let urlDistinctParams = ''
if (urlParams) {
urlParams.split('&').forEach((e) => {
let [key, val] = e.split('=');
if (!paramsToStrip || !paramsToStrip.includes(key)) {
if (!paramKVMap[key]) {
// http://stackoverflow.com/questions/8002252/euler-project-18-approach
function longestSlideDown (pyramid) {
let pyramidSum = [];
pyramid.forEach((r, i) => {
pyramidSum.push(r.map((e) => {
return (i === pyramid.length - 1) ? e : 0;
}));
});
for (let i = pyramidSum.length - 2; i >= 0; i--) {
function convert(input, source, target) {
if (source === target) {
return input;
}
// Compute the value of the input in source base
// then convert it to value in target base
let sourceValue = input.split('').reverse().reduce( (acc, val, digitPos) => {
return acc + Math.pow(source.length, digitPos) * source.indexOf(val);
}, 0);
function sierpinski(n) {
if (n === 0) {
return 'L';
}
let tri = sierpinski(n - 1);
let triRows = tri.split('\n');
let gap = 2 * triRows.length - 1;
let arr = triRows.reduce((arr, r) => {
arr.push(r + ' '.repeat(gap) + r);
function decode(str) {
var result = [];
let idx = 0;
let charCount = 0;
let strCharCount = '';
while (idx < str.length) {
if (str[idx] === '\\') {
// parse digits
strCharCount = '';
idx += 1;
var maxSequence = function(arr){
let isAllNegative = arr.every((e) => e < 0);
if (arr.length === 0 || isAllNegative) {
return 0;
}
let isAllPositive = arr.every((e) => e > 0);
if (isAllPositive) {
return arr.reduce((a,b) => { return a + b }, 0);
}
array_diff = (a, b) ->
diff_array = []
for e in a
if e not in b then diff_array.push e
diff_array
printerError = (s) ->
goodAlphabet = "abcdefghijklm"
errorCount = 0
for x in s
if x not in goodAlphabet then errorCount += 1
"#{errorCount}/#{s.length}"
function chainFunctions(fns) {
for (let fname in fns) {
let originalFn = fns[fname];
let fn = (...inputs) => {
if (this.result != null) {
inputs.splice(0, 0, this.result);
}
let cloneCF = new chainFunctions(fns);
cloneCF.result = originalFn.apply(this, inputs);
return cloneCF
//https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29
// http://stackoverflow.com/questions/17438595/js-non-enumerable-function
function LRUCache(capacity, init) {
this.nextTime = 0;
this.storage = [];
this.initialCapacity = capacity;
Object.defineProperty(this, 'nextTime', { enumerable: false });
Object.defineProperty(this, 'storage', { enumerable: false });
Object.defineProperty(this, 'initialCapacity', { enumerable: false });