Skip to content

Instantly share code, notes, and snippets.

View danielpcox's full-sized avatar

Daniel Cox danielpcox

View GitHub Profile
@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 / 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 / sample.rb
Created August 14, 2009 18:46
Array#sample : I recently moved a project from ruby 1.9.1 to ruby 1.8.6, which doesn't have Array#sample. I couldn't find it online quickly, so I wrote one.
# Array#sample
# I recently moved a project from ruby 1.9.1 to ruby 1.8.6, which doesn't have
# Array#sample. I couldn't find it online quickly, so I wrote one.
class Array
def sample(sample_size=1, acc=[])
sample_size = self.size if acc.empty? && sample_size > self.size
return acc if sample_size==0
index_to_sample = (rand * self.size).floor
if acc.include?(self[index_to_sample])
find -iname "*.html" -exec sh -cC '
sed 's/search/replace/' "$1" > "$1".new
' {} {} \;
alias g='gvim --remote-silent'
alias fri='ri'
alias lh='ls --color=always -lasth | less -R'
alias be='bundle exec'
alias gr='grep -r --color'
alias rm='gvfs-trash'
@danielpcox
danielpcox / _items.html.erb
Created July 13, 2010 22:58
a DRY and unobtrusive way to use will_paginate with ajax via jQuery
<!-- app/views/items/_items.html.erb -->
<ul>
<% items.each do |item| %>
<li><%= item.name %></li>
<% end %>
</ul>
<%= ajax_will_paginate items, :update => 'my_items_list' %>
@danielpcox
danielpcox / rmt.rb
Created April 16, 2011 02:33
Generates my ORIE 3800 HW5 homework (database connection code omitted)
#!/home/danielpcox/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
require 'active_record'
require './ticket'
require './extra'
require './show_info'
require 'gruff'
conn_params = {
@danielpcox
danielpcox / parameters_in_dryml.dryml
Created September 16, 2011 22:28
Parametrized Tags In DRYML
<!-- defining a tag -->
<def tag="messages">
<br /><br />
<ul>
<li param="msg1">Message 1</li>
<li param="msg2">Message 2</li>
<li param="msg3">Message 3</li>
</ul>
</def>