Skip to content

Instantly share code, notes, and snippets.

const { SharedIniFileCredentials, STS } = require('aws-sdk')
const { execSync } = require('child_process')
const OK_RESPONSE = /button returned:OK, text returned:(?<answer>\S+)/
async function tokenCodeAppleScript (serialno, callback) {
try {
const cmd = `osascript -e 'display dialog "Enter MFA code for ${serialno}:" default answer ""'`
const response = execSync(cmd).toString()
const match = response.match(OK_RESPONSE)
@jhecking
jhecking / bins.rs
Last active September 4, 2018 11:32
#[derive(Debug)]
pub struct Bin<'a> {
/// Bin name
pub name: &'a str,
/// Bin value
pub value: i64,
}
impl<'a> Bin<'a> {
@jhecking
jhecking / benchmark
Last active August 25, 2016 08:29
Optimizing handling for variadic function arguments
#!/bin/bash
node benchmark.js
@jhecking
jhecking / udfFilter.go
Last active August 24, 2016 16:55
Aerospike Go client example for Aggregate Query
package main
import (
"fmt"
. "github.com/aerospike/aerospike-client-go"
)
func panicOnError(err error) {
if err != nil {
panic(err)

Keybase proof

I hereby claim:

  • I am jhecking on github.
  • I am jhecking (https://keybase.io/jhecking) on keybase.
  • I have a public key ASBbEfvjjpqSfK2DKgiSaueL3k5nIwA4-u505AapHjgDfQo

To claim this, I am signing this object:

@jhecking
jhecking / index.js
Created April 14, 2016 18:16
Aerospike Node.js v1 Aggregation Query Example
var aerospike = require('aerospike')
var config = {log: {level: 3} }
var ns = 'test'
var set = 'demo'
aerospike.client(config).connect(function (error, client) {
client.put({ns: ns, set: set, key: 'k1'}, {i: 1}, function (error) {
if (error && error.code !== 0) throw new Error(error.message)
client.udfRegister('udf.lua', function (error) {
if (error && error.code !== 0) throw new Error(error.message)
@jhecking
jhecking / agg.js
Last active April 4, 2016 09:12
Example of Aerospike aggregation query with Lua aggregation function using Aerospike Node.js client
const Aerospike = require('aerospike')
const config = {
hosts: '192.168.33.10:3000',
log: { level: 5 },
modlua: {
userPath: './',
systemPath: './node_modules/aerospike/aerospike-client-c/lua/'
}
}
@jhecking
jhecking / world_regions.yml
Created May 28, 2014 09:58
List of the world's regions and their countries in YAML format - Source: http://geography.about.com/od/lists/a/officiallist.htm
world_regions:
asia:
name: Asia
countries:
- BD
- BT
- BN
- KH
- CN
- IN
@jhecking
jhecking / exception_hierarchy.rb
Last active December 28, 2015 23:19
Slightly adapted version of Nick Sieger's script to dump Ruby's exception hierarchy. If run with `bundle exec` or `rails console` the hierarchy will include all exception classes defined in any of the included gems as well. Therefore I found it necessary to determine the common ancestors of the Exception class at run-time rather than hard code t…
def class_hierarchy(root, exclude = [])
common_ancestors = root.ancestors.drop(1)
descendants = []
tree = {}
ObjectSpace.each_object(Class) do |cls|
next unless cls.ancestors.include? root
next if descendants.include? cls
case exclude
when Class, Array
next unless (Array(exclude) & cls.ancestors).empty?
@jhecking
jhecking / gist:4070551
Created November 14, 2012 05:53
Phone number regular expression
# A phone number consists of up to six groups of digits which may or may not
# be separated from each other using one of the separater characters dot ".",
# dash "-" or space " ". The six groups are:
# (1) International country code, which is a one to four digit number
# prefixed by a plus sign "+". The plus sign is optional if - and only if -
# the country code is immediately followed by a separator char.
# The whole country code group is optional.
# (2) Area code, which is a one to three digit number enclosed in parenthesis
# "()". The parenthesis are optional if - and only if - the area code is
# immediately followed by a separator char.