Skip to content

Instantly share code, notes, and snippets.

View davidhq's full-sized avatar
🎯
Focusing

davidhq

🎯
Focusing
View GitHub Profile
@davidhq
davidhq / json-diff.js
Last active December 12, 2019 17:14
json-diff.js
import { applyPatch } from 'fast-json-patch/index.mjs';
import justDiff from 'just-diff';
const { diff, jsonPatchPathConverter } = justDiff;
const doc = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
const patch = diff(doc, [], jsonPatchPathConverter);
console.log(patch);
@davidhq
davidhq / batman_hooks.js
Last active October 10, 2019 10:59
batman hooks
// Batman shooting dmt-fibers with a grapple gun
//
// _____ _____
// ,-'``_.-'` \ / `'-._``'-.
// ,` .' |`-'| `. `.
// ,` ( /\ | | /\ ) `.
// / `--' `-' `-' `--' \
// | |
// \ .--. ,--. ,--. ,--. /
// `. ( \/ lt.\ / \/ ) ,'
# Function
function:
- match: \b(function)\s+({{identifier}})
captures:
1: storage.type.function
2: entity.name.function
push:
- function-body
- returns-declaration
const crypto = require('crypto');
function lpad(str, padString, length) {
while (str.length < length) str = padString + str;
return str;
}
// converts string '110' to integer 6
function binaryToByte(bin) {
return parseInt(bin, 2);
@davidhq
davidhq / excel_magic.js
Last active October 8, 2023 02:03
Execute excel workbooks through node.js
const FormulaParser = require('hot-formula-parser').Parser;
const parser = new FormulaParser();
const Excel = require('exceljs');
const workbook = new Excel.Workbook();
function getCellResult(worksheet, cellLabel) {
if (worksheet.getCell(cellLabel).formula) {
return parser.parse(worksheet.getCell(cellLabel).formula).result;
} else {
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include "ota.h"
#include "sounds.h"
WiFiServer server(80);
const char* ssid = "ssid";
@davidhq
davidhq / ethInquireClients.js
Last active June 12, 2017 17:48
get the report on active local Ethereum clients (client version and latest block)
#!/usr/bin/env node
var colors = require('colors'); // npm install colors
var moment = require('moment'); // npm install moment
var Web3 = require('web3'); // npm install web3
let port = process.argv[2];
function tryWeb3(port) {
let web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider(`http://localhost:${port}`));
@davidhq
davidhq / gravity.elm
Last active March 31, 2016 21:27 — forked from JoelQ/Ball.elm
Gravity and Ball
-- https://gist.github.com/davidhq/eae55136adc1973b524f7b41746b78ac
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Color exposing (..)
import Keyboard
import Time
import Debug
-- Model
type alias Model = { x : Float, y : Float, radius: Float }
# Window toggling (switch back and forth between last two focused windows) for Sublime
# Add to Key Bindings - User:
# {
# "keys": ["f3"],
# "command": "toggle_windows"
# },
# then put toggle_windows.py (this file) into ~/Library/Application Support/Sublime Text 3/Packages/User
import os
import sublime
# git helpers - davidhq
function git_repo {
local root=$(git rev-parse --show-toplevel || echo ".")
local cwd=`pwd`
cd $root
local origin=$(git remote -v | grep origin | grep push | sed 's/origin//g' | sed 's/git@github.com://g' | sed 's/https:\/\/github.com\///g' | sed 's/.git (push)//g' | xargs)
cd $cwd
eval "$1=$origin"
}