Skip to content

Instantly share code, notes, and snippets.

View dpritchett's full-sized avatar
🦅
microservice party

Daniel Pritchett ⚡ dpritchett

🦅
microservice party
View GitHub Profile
@dpritchett
dpritchett / sorted.sh
Created May 10, 2011 21:29
Sort each row in this wordcounts text file by second field descending
# sort -rk 2 gets reverse sort order, key = 2nd field
cat ./output/* | sort -rk 2 | more
@dpritchett
dpritchett / git_log_munge.sh
Created May 10, 2011 21:31
Simulate git log --oneline
# grep -vE removes lines matching the following expression
# sed is trimming leading whitespace
# awk is prepending "* " to each line ($0 is the entire line)
git log | grep -vE '^(Author|Date|commit|\w*$)' | sed 's/^\s*//g' | awk '{print "* " $0}' | head -10
@dpritchett
dpritchett / mkdir repeatedly.sh
Created May 10, 2011 21:35
simple use of xargs to streamline a series of mkdir ops
mkdir playground
mkdir playground/src
mkdir playground/classes
echo playground playground/src playground/classes | xargs mkdir
# mkdir: cannot create directory `playground': File exists
# mkdir: cannot create directory `playground/src': File exists
# mkdir: cannot create directory `playground/classes': File exists
# Bonus points for DRYing the "playground" part...?
def __boardLog(self):
"""Returns the absolute path to the server logfile as a string.
"""
logFile = '''//{path}/c$/Board/Dataset/Log/Dtb_{dbname}_{date}.log'''.format(
path = self.board_server
, dbname = self.dbname
, date = date.today().strftime('%Y%m'))
return logFile
@dpritchett
dpritchett / count_lines.rb
Created June 9, 2011 15:04
Deduplicate a sorted CSV file, adding a rowcount column
def clean_line some_text
# Takes a comma delimited string, returns an array of fields with leading
# and trailing whitespace stripped out.
some_text.gsub(/\"|\n/, "").split(',').each { |x| x.strip! }
end
def spit_line counter, some_line
# Takes a counter and an array of strings, prints them in counter,strings
# CSV format.
print "#{counter}"
game_log = new Array();
go = function (){
x = Math.floor(Math.random() * 11) + Math.floor(Math.random() * 11);
return x;
};
execute_n_times = function(n) {
for( i = 0; i < n; i++){
single_roll = go();
jQuery ($) ->
window.Plant = Backbone.Model.extend
testFun: (name) ->
return "Hello, #{name}"
vitals: ->
return @get 'vitals'
window.PlantView = Backbone.View.extend
tag : 'li'
className : 'plant'
@dpritchett
dpritchett / sms_myself.py
Created July 24, 2011 18:54
Sending a text message via Twilio using Python or Ruby
#!/usr/bin/env python
"""
REQUIREMENTS:
* A Twilio account
* Python with the twilio library (`pip install twilio`)
* A purchased phone number on twilio to serve as your "from" number ($1/mo)
* Some twilio credits to pay for the $.01/msg SMS fees
The python-twilio library uses OS-level environment variables
@dpritchett
dpritchett / SMSSender.rb
Created July 25, 2011 18:16
Ruby class for sending myself SMSes
require 'twilio-ruby'
class SMSSender
def initialize
# put your own credentials here
@account_sid = ENV['TWILIO_ACCOUNT_SID']
@auth_token = ENV['TWILIO_AUTH_TOKEN']
@SMS_RECIPIENT = "+REDACTED" # My google voice number
@SMS_SENDER = "+REDACTED" # My paid twilio number
@dpritchett
dpritchett / gnotify
Created August 29, 2011 21:43
Growl under Windows
#!/usr/bin/env ruby
require 'rubygems'
require 'ruby_gntp'
GNTP.notify({
:app_name => "CLI Alert",
:title => "CLI Alert",
:text => ARGV.join(' '),
})