Skip to content

Instantly share code, notes, and snippets.

Daniel Cox danielpcox

Block or report user

Report or block danielpcox

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@danielpcox
danielpcox / sample.rb
Created Aug 14, 2009
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.
View sample.rb
# 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])
View find_and_replace.sed
find -iname "*.html" -exec sh -cC '
sed 's/search/replace/' "$1" > "$1".new
' {} {} \;
View .bash_aliases
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 Jul 13, 2010
a DRY and unobtrusive way to use will_paginate with ajax via jQuery
View _items.html.erb
<!-- 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 Apr 16, 2011
Generates my ORIE 3800 HW5 homework (database connection code omitted)
View rmt.rb
#!/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 Sep 16, 2011
Parametrized Tags In DRYML
View parameters_in_dryml.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>
View gist:1299083
1. e4 c6
2. Bc4 d5
3. Bd3 e5
4. Nf3 Bg4
5. Nc3 Nd7
6. exd5 Bb4
7. Qe2 c5
8. Nb5 h5
9. a3 h4
10. axb4 f6
@danielpcox
danielpcox / pidgin_manipulator.rb
Created Oct 22, 2011
Set Your Pidgin Status With Ruby and DBus
View pidgin_manipulator.rb
#!/usr/bin/env ruby
#
require "dbus"
session_bus = DBus::SessionBus.instance
# Get the Pidgin Service
pidgin_dbus = session_bus.service("im.pidgin.purple.PurpleService")
# Get the object from this service
You can’t perform that action at this time.