Skip to content

Instantly share code, notes, and snippets.

View wickkidd's full-sized avatar

Brian Kidd wickkidd

  • Washington DC
View GitHub Profile
import alias from '@rollup/plugin-alias'
import analyze from 'rollup-plugin-analyzer'
import requireContext from 'rollup-plugin-require-context'
import sass from 'rollup-plugin-sass'
import typescript from 'rollup-plugin-typescript2'
import VuePlugin from 'rollup-plugin-vue'
import fs from 'fs'
import path from 'path'
@wickkidd
wickkidd / get-properties.js
Created June 9, 2020 14:57
js get object properties (incl inherited)
const getMethods = (obj) => {
let properties = new Set()
let currentObj = obj
do {
Object.getOwnPropertyNames(currentObj).map(item => properties.add(item))
} while ((currentObj = Object.getPrototypeOf(currentObj)))
return [...properties.keys()].filter(item => typeof obj[item] === 'function')
}
@wickkidd
wickkidd / TimeCop.java
Created January 6, 2020 17:30
TimeCop::freezeDuring static method that freezes time during the execution of the passed lambda (Runnable). Idea stolen from my days as a ruby dev https://github.com/travisjeffery/timecop
package my.awesome.namespace;
import org.joda.time.DateTime;
import org.joda.time.DateTimeUtils;
public class TimeCop {
public static void freezeDuring(Runnable block) {
DateTimeUtils.setCurrentMillisFixed(DateTime.now().getMillis());
block.run();
@wickkidd
wickkidd / group-by.js
Created December 12, 2019 19:29
esNext groupBy()
groupBy(array, property) {
return array.reduce(function(rv, x) {
(rv[x[property]] = rv[x[property]] || []).push(x)
return rv
}, {})
}
@wickkidd
wickkidd / replace_text.py
Created March 19, 2019 15:23
I wanted to replace string matches with the output of piped shell commands
# python
import subprocess
import re
o = open("some_html_file.out.html","w")
data = open("./some_html_file.html").read()
def gen_id(match):
match = match.group()
id = subprocess.getoutput("cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 4")