Skip to content

Instantly share code, notes, and snippets.

View dsernst's full-sized avatar
🧘‍♂️
practicing mindfulness

David Ernst dsernst

🧘‍♂️
practicing mindfulness
View GitHub Profile
@dsernst
dsernst / stache-calc.js
Last active October 8, 2015 08:15
Code to calculate weekly 'stache growth
/* eslint-env node */
module['exports'] = function echoHttp (hook) {
console.log('hook.req', hook.req.method)
// console.log('hook.params', hook.params['attachment-1']['body-plain'])
console.log('hook.params', hook.params)
if (hook.req.method === 'POST') {
console.log('in POST request')
}
@dsernst
dsernst / osx_dockerhost.sh
Created October 8, 2015 07:22
Use `dockerhost` instead of the IP of your docker-machine vm
echo $(docker-machine ip default) dockerhost | sudo tee -a /etc/hosts
@dsernst
dsernst / say-before.git.sh
Created September 5, 2015 22:30
Example of modifying git to do something else before it runs
# Add this to the top of your .bash_profile
git () {
say "git";
/usr/local/bin/git "$@";
}
@dsernst
dsernst / measure-logging-speeds.md
Last active September 5, 2015 03:46
Speed testing node's default console.log, versus an async logger, versus no logging.

Tested with the looping going up to n <= 65

node-simplelogger: 12.2s (with slight delay after it finished printing before the process ended)
no logging: 10.6s
console.log: 12.8s

These measurements came from adjust line 33 of this file: https://github.com/dsernst/ProjectEuler/blob/67a9c17f0810ff6a5da5c20c027e8c11c7a0c304/53%20Combinatoric%20selections.js#L33

The point of these tests were to see if using an asyncronous logger would be faster than node's built in console. In this case, it did not make a meaningful difference.

@dsernst
dsernst / .eslintrc
Last active September 5, 2015 23:29
~/.eslintrc
{
"rules": {
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"comma-dangle": [1, "always-multiline"],
"indent": [1, 2],
"new-cap": 1,
"no-alert": 1,
"no-console": 1,
"no-debugger": 1,
"no-dupe-args": 2,
@dsernst
dsernst / os-specific-node_modules-packages.md
Last active November 4, 2015 07:58
How to use distinct npm packages across a host & VM when using a shared project folder

How to use distinctly compiled npm packages across a host machine & VM with a shared project folder

Use bcrypt and mongoose in each, with their own, OS-specific bindings
  1. Go to your ~/ home directory on the machine you want to install OS-specific module for, then run $ npm i compiled-package

  2. Move your package into ~/.node_modules folder (this is a special folder node knows to look in when requireing modules)

  • So probably: $ mv ~/node_modules/compiled-package ~/.node_modules/compiled-package
    • Shorthand: $ mv ~/{,.}node_modules/compiled-package
  • (consider rm -rfing the first node_modules folder to clean up after yourself)
@dsernst
dsernst / getSpreadsheetData.js
Last active February 21, 2019 04:31
getSpreadsheetData() utility function takes the name of a worksheet, then grabs all the data on the page and gives you back an array of objects, with the first row as property names.
function getSpreadsheetData(sheetName) {
// This function gives you an array of objects modeling a worksheet's tabular data, where the first items — column headers — become the property names.
var arrayOfArrays = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName || 'Sheet1').getDataRange().getValues();
var headers = arrayOfArrays.shift();
return arrayOfArrays.map(function (row) {
return row.reduce(function (memo, value, index) {
if (value) {
memo[headers[index]] = value;
}
return memo;
@dsernst
dsernst / squares.c
Created June 16, 2015 20:12
Compiling some C
#include<stdio.h>
void squares(int v)
{
for (int i=1;i<v+1;i++) {
printf("%d ", i*i);
}
printf("\n");
}
@dsernst
dsernst / Google Apps Script.md
Last active August 29, 2015 14:22
Outline from my "Google Apps Script" Lightning Talk @ Hack Reactor

Lightning Talk: Google Apps Script

  • What is Google Apps Script
    • Homepage: https://developers.google.com/apps-script/
    • Extend Google Apps: "Increase the power of your favorite Google apps — like Calendar, Docs, Drive, Gmail, and Sheets. Apps Script lets you do more with Google. All on a JavaScript platform in the cloud."
    • Written in Javascript
      • with lots of new Globals
      • everything is synchronous, no callbacks
      • have to use the Apps Script IDE
  • Runs on Google servers
@dsernst
dsernst / quicksort.hs
Created June 8, 2015 03:30
@nsluss shows me how to compile my first Haskell program
qs :: (Ord a) => [a] -> [a]
qs [] = []
qs (x:xs) = qs (lessThan x xs) ++ [x] ++ qs (greaterThan x xs)
where lessThan val ys = [y | y <- ys, val >= y]
greaterThan val ys = [y | y <- ys, val < y]