Skip to content

Instantly share code, notes, and snippets.

View danielpcox's full-sized avatar

Daniel Cox danielpcox

View GitHub Profile
@danielpcox
danielpcox / Config.java
Created July 4, 2013 15:56
Simple, static, global configuration. Depends on Log4j and Guava.
package rmt.analytics.tagger.configuration;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@danielpcox
danielpcox / retrync
Last active December 21, 2015 13:19
retrync ("retrying rsync") executes resumable rsync uploading/downloading via SSH with progress over and over until the transfer is complete. First stick your public SSH key in ~/.ssh/authorized_keys on the remote server. Original version came from http://blog.iangreenleaf.com/2009/03/rsync-and-retrying-until-we-get-it.html
#!/bin/bash
# Usage: retrync path/to/thing/locally user@host:/path/where/you/want/it/remotely
trap "echo Exited!; exit;" SIGINT SIGTERM
false
while [ $? -ne 0 ]
do
@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

@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 / 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 / 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 / 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 / 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)
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("")}
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := 1.0
l := 0.0