Skip to content

Instantly share code, notes, and snippets.

View louisbuchbinder's full-sized avatar

Louis Buchbinder louisbuchbinder

View GitHub Profile
@louisbuchbinder
louisbuchbinder / #FibonacciTwisp
Last active May 12, 2022 15:37
Twisp Trigger Fibonacci
This is a contrived example to demonstrate transaction triggers in Twisp.
@louisbuchbinder
louisbuchbinder / astFuncParser.go
Last active April 28, 2022 17:29
Parse Function Comments From Source in Golang
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"log"
)
@louisbuchbinder
louisbuchbinder / input.js
Created July 13, 2017 03:27
Browser Files
if (!File) {
throw new Error('Unsupported Browser. File is required.');
}
function input(callback) {
var element = document.createElement('input');
element.setAttribute('type', 'file');
element.setAttribute('multiple', '');
// &&
if (true && true && true) // TRUTHY
if (true * true * true) // using multiplication converts true to 1 and multiplies each 1 together, (1 * 1 * 1) which evaluates to a truthy value
if (true && true && false) // FALSY
if (true * true * false) // (1 * 1 * 0) FALSY
// ||
{
"node": true,
"browser": true,
"esversion": 6,
"bitwise": true,
"curly": true,
"eqeqeq": true,
"forin": true,
"freeze": true,
"futurehostile": true,
@louisbuchbinder
louisbuchbinder / index.js
Created June 7, 2016 19:01
Clever average students per section
// rl-stdin is a node module I wrote to the stdin data and resolve the result in a promise
// `sudo npm install -g rl-stdin`
require('rl-stdin') // get the stdin data from the curl
.then(JSON.parse) // convert JSON to javascript object
.then((data) => data.data) // data is stored at the data key
.then((data) => data.map((section) => section.data.students.length)) // map the section to the number of students enrolled
.then((data) => data.reduce((hold, current) => hold + current)/data.length) // sum the total number of students enrolled divided by the total number of sections to get the average
.then((solution) => console.log('Average students per section is: ' + solution)); // log the output
@louisbuchbinder
louisbuchbinder / delete.sh
Last active June 6, 2016 15:03
Stop using rm!! Safely move files to the trash instead using delete.
#!/bin/bash
if [[ $1 = "-trash" ]] || [[ $1 = "-t" ]]
then
while true
do read -p "Are you sure you want to permanently delete the trash? (yes/no): " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo "Aborted the operation"; exit 0;;
* ) echo "Please answer yes or no. Do you want to permanently delete the trash? (yes/no)";;
@louisbuchbinder
louisbuchbinder / html-init.sh
Created June 6, 2016 02:16
Initialize html repo
#!/bin/bash
html="
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="app.css">
</head>
<body>