Skip to content

Instantly share code, notes, and snippets.

View danielpcox's full-sized avatar

Daniel Cox danielpcox

View GitHub Profile
@danielpcox
danielpcox / PongPreprocessing.ipynb
Created July 3, 2018 22:49
Preprocessing examples for OpenAI Gym environments
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danielpcox
danielpcox / post-merge
Last active December 30, 2016 17:40 — forked from sindresorhus/post-merge
git hook to run a command after `git pull` if a specified file was changed.In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#!/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := 1.0
l := 0.0
def hex_to_bytes(str)
str.chars.each_slice(2).map {|s| s.join.to_i(16)}
end
def hex_to_bits(str)
str.chars.each_slice(2).flat_map {|s| s.join.to_i(16).to_s(2).rjust(8,"0").split("")}
end
def bytes_to_binary(bytes)
bytes.flat_map {|b| b.to_s(2).rjust(8,"0").split("")}
@danielpcox
danielpcox / rotate.clj
Last active August 29, 2015 14:25
Rotate Sequence
; Solving 4Clojure 44
; first try
(def rotate
(fn [n xs]
(if (= n 0)
xs
(let [nextn (* (dec (Math/abs n)) (if (< n 0) -1 1))
nextxs (and (not= 0 n)
(if (< n 0)
@danielpcox
danielpcox / deep-merge-spec.clj
Created March 11, 2015 21:21
Simple, recursive deep-merge in Clojure.
(ns deep-merge-spec
(:require [midje.sweet :refer :all]
[util :as u]))
(fact (u/deep-merge {:one 1 :two 2}
{:one 1 :two {}})
=> {:one 1 :two {}})
(fact (u/deep-merge {:one 1 :two {:three 3 :four {:five 5}}}
{:two {:three {:test true}}})
@danielpcox
danielpcox / keybase.md
Created February 12, 2015 02:55
Keybase.io identity proof

Keybase proof

I hereby claim:

  • I am danielpcox on github.
  • I am danielpcox (https://keybase.io/danielpcox) on keybase.
  • I have a public key whose fingerprint is D085 A81C CE7C 291D 7A9E 1F70 14DA 0F0F BB08 2FEE

To claim this, I am signing this object:

@danielpcox
danielpcox / allpanes.sh
Created April 24, 2014 20:10
Run a command in all tmux panes of the current window
#!/bin/bash
# Runs the specified command (all arguments together) in all tmux panes in the current window
# Notate which window/pane we were originally at
window=`tmux display-message -p '#I'`
ORIG_PANE_INDEX=`tmux display-message -p '#P'`
command=$@
@danielpcox
danielpcox / extract_subdir_slim_history.txt
Last active August 29, 2015 13:56
Extract subdirectory in git, then slim down the history
$ git clone blahblahblah # <-- fresh clone of the repo
$ du -sh .
768M # <-- holy macaroni, that's huge
$ git filter-branch --subdirectory-filter path/to/subdir --prune-empty --tag-name-filter cat -- --all # <-- Actual filter
...
### Now we'll delete all references to those unchanged refs
$ git reflog expire --expire=now --all # <-- expire the reflog refs
@danielpcox
danielpcox / README.md
Last active December 25, 2015 21:29
Simple Dev Box

Simple Dev Box

Spins up a very simple VM and installs a few important things.

Usage