Skip to content

Instantly share code, notes, and snippets.

@BeejLuig
BeejLuig / csv_to_json.js
Created March 20, 2020 17:28
Converts a csv file to json
const path = require('path');
const fs = require('fs');
const csvToJson = csv => {
const [keys, ...rows] = csv
.split("\n")
.map(row => row.split(","))
.slice(0, -1);
return rows.map(row =>
row.reduce(
@BeejLuig
BeejLuig / execute.js
Created July 5, 2019 17:56
Node helper to execute multiple lines of shell script
const { execSync: exec } = require('child_process');
/**
Executes multiple lines of script.
@param {String} scriptStr - A single or multi-line string of executable code
@example
execute(`
echo 'Hello'
echo 'World'
echo '!'
@BeejLuig
BeejLuig / zero-balanced.js
Last active October 11, 2017 02:51
Zero Balanced Array
/*
* An array is called zero-balanced if its elements sum to 0 and for each positive element n,
* there exists another element that is the negative of n. Write a function named ìsZeroBalanced that returns true
* if its argument is zero-balanced array, else return false. Note that an empty array will not sum to zero.
*/
function isZeroBalanced(a){
return a.length > 0 && a.every(x => a.includes(-x)) && a.reduce((acc, x) => acc + x) === 0
}
@BeejLuig
BeejLuig / sort_by_call_number.js
Last active June 20, 2017 19:24
Google Apps Script - Sort by Call Number
//add menu called "Extras" with a sort button
function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu("Extras")
.addItem("Sort by LOC", 'sortRange')
.addToUi();
}
@BeejLuig
BeejLuig / gin-rummy
Created May 28, 2017 23:04
Gin rummy score keeper CLI
class Game
attr_accessor :players, :round, :counter
def initialize
@players = Player.all
@round = 1
@counter = 0
end
def next_round
@BeejLuig
BeejLuig / 0_reuse_code.js
Created February 19, 2017 22:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console