Skip to content

Instantly share code, notes, and snippets.

View steinfletcher's full-sized avatar

Stein steinfletcher

  • Oxford, United Kingdom
  • 21:56 (UTC +01:00)
View GitHub Profile
@steinfletcher
steinfletcher / jstree.py
Last active February 17, 2024 11:38
file system crawler to generate object tree json data for jsTree [http://www.jstree.com/]
#!/usr/bin/env python
import os
import json
class Node:
def __init__(self, id, text, parent):

Keybase proof

I hereby claim:

  • I am steinfletcher on github.
  • I am steinf (https://keybase.io/steinf) on keybase.
  • I have a public key ASBe2QIkh72SEFeu8ItJno1R7NoHu9-hSY_LknXTOfK0hAo

To claim this, I am signing this object:

@steinfletcher
steinfletcher / words.hs
Last active November 4, 2019 20:35
Count words in file in Haskell
import Control.Exception
import System.Environment (getArgs)
catchAny :: IO a -> (SomeException -> IO a) -> IO a
catchAny = Control.Exception.catch
parseArgs :: [a] -> a
parseArgs args
| (length args) == 1 = head args
| otherwise = error "Invalid args. \nUsage: words <file>"
@steinfletcher
steinfletcher / traverse.js
Last active November 17, 2018 20:11
Object tree traversal in javascript (with lodash)
var data = {
"name": "root",
"contents": [
{
"name": "A",
"contents": [
{
"name": "fileA1",
"contents": []
}
@steinfletcher
steinfletcher / model.ts
Last active July 13, 2018 07:53
React Redux Typescript Template
import * as React from 'react'
import * as Redux from 'redux'
import { MyReduxState } from './my-root-reducer.ts'
export interface OwnProps {
propFromParent: number
}
interface StateProps {
@steinfletcher
steinfletcher / team_clone.py
Last active May 14, 2017 09:59
Clone all repositories owned by a GitHub organisation team
import base64
import json
import optparse
import os
import urllib2
from subprocess import call
from threading import Thread
"""Script to clone all GitHub repositories owned by an organisation team
@steinfletcher
steinfletcher / keygen.sh
Created August 20, 2016 15:06
Generate public and private key pair
#!/usr/bin/env bash
# generate a 2048-bit RSA private key
openssl genrsa -out private_tmp_key.pem 2048
# convert private Key to PKCS#8 format (so Java can read it)
openssl pkcs8 -topk8 -inform PEM -in private_tmp_key.pem -out private_key.pem -nocrypt
# generate a public key from the private one
openssl rsa -pubout -in private_tmp_key.pem -out public_key.pem
@steinfletcher
steinfletcher / immutableMerge.js
Created August 21, 2014 07:52
lodash merge that doesn't modify the source object
_.mixin({
'immutableMerge': function(src, dest) {
return _.merge(_.cloneDeep(src), dest);
}
});
// usage
var src = {
a: 1,
@steinfletcher
steinfletcher / alias.bash
Last active August 29, 2015 14:09
git aliases (taken from zsh)
alias g='git'
alias gst='git status'
alias gd='git diff'
alias gdc='git diff --cached'
alias gdt='git diff-tree --no-commit-id --name-only -r'
alias gl='git pull'
alias gup='git pull --rebase'
alias gp='git push'
alias gd='git diff'
alias gdt='git difftool'
@steinfletcher
steinfletcher / change_mac_address.bash
Last active August 29, 2015 14:03
Change the mac address of a device (useful for various spoofing, e.g. for extending limited access on public wifi networks). Tested in OSX
#!/bin/bash
# Author: Stein Fletcher <steinfletcher@gmail.com>
# Purpose: Changes the mac address for the en0 device
# get the current mac address
old_addr=`/sbin/ifconfig en0 | awk '/ether/ {print $2}'`
# Generates a random new mac address using openssl
new_addr=`openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'`