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 / What.py
Created November 19, 2010 21:06
pretend port of mike's What.js to python
# Compare to https://github.com/entmike/What/blob/master/libs/What.js
import http #note, this lib doesn't exist in python, maybe BaseHTTPServer would work here?
from urlparse import urlparse
print([
"",
"o `O o oO ",
"O o O OO ",
"o O o O oO ",
@dpritchett
dpritchett / xcopy.cmd
Created February 25, 2011 17:14
xcopy.cmd
@echo Copying changed files
@xcopy \\webservername\d$\screwturn_wiki h:\screwturn_backup /E /Y /X /K /D
pause
@dpritchett
dpritchett / board_logger.sh
Created February 25, 2011 17:16
pull today's logs out of a monthly rotating logfile
#!/bin/bash
DATE=`date +%Y%m%d`
if [ "$1" == "" ]; then
WORKDIR=~/Board
SERVER=prod
echo 'Pulling PRODUCTION log'
else
WORKDIR=~/BoardDev
SERVER=dev
@dpritchett
dpritchett / clone_folder_from_production.cmd
Created March 1, 2011 21:52
Clone a folder from one windows server to another using xcopy (plus rmdir and service restarts)
@echo ******** STOPPING BOARD SERVICES ********
@rem sc \\productionservername stop board7
@rem sc stop board7
@echo ******** CLONING PLANNING DATABASE FROM PROD TO DEV ********
C:
CD \Board\Database
rmdir /s /q ".\database_name.dtbx"
dir
@pause
@dpritchett
dpritchett / pyodbc_example.py
Created March 24, 2011 13:40
Sample pyodbc code to read a log table out of SQL Server
import pyodbc
cnxn = pyodbc.connect('DSN=production_rdmbs')
cursor = cnxn.cursor()
cursor.execute("SELECT [Trigger_Name] \
,[Table_Ready] \
,[Date_Modified] \
FROM triggers_table_name")
rows = cursor.fetchall()
@dpritchett
dpritchett / 1) job-site-renderer.coffee
Created April 19, 2011 18:56
coffeescript jobsite renderer
$(document).ready ->
jobloader.initialize()
window.jobloader =
pulljobs: (callback) ->
$.getJSON '/jobs.json',
(data) ->
callback data
printjobs: (data) ->
@dpritchett
dpritchett / (1) lines_per_day.rb
Created April 21, 2011 19:45
lines_per_day.rb
#!/usr/bin/ruby
# Needed to figure out the daily load on our reporting server. Decided to hit the monthly log file
# and see how many lines per day were being written to it. This was a good excuse to test out some
# new Ruby learning.
logfile = ARGV[0]
101.upto(131) do |day|
day = day.to_s[1..2]
print "April #{day}:\t"
@dpritchett
dpritchett / fizzbuzz.rb
Created April 23, 2011 00:11
[fizzbuzz.rb] Apologies to rubyquiz.com; I synthesized some of my favorite fizzbuzzes
1.upto(100) do |x|
return_value = ''
return_value << "Fizz" if x.modulo(3).zero?
return_value << "Buzz" if x.modulo(5).zero?
return_value << x.to_s if return_value.empty?
puts "[#{x}]\t#{return_value}"
end
"""
<< Results copied from an irb session >>
@dpritchett
dpritchett / lines_per_log.rb
Created April 28, 2011 16:05
Line count of daily logfiles in a given folder
#!/usr/bin/ruby
require 'date'
PATH = "//server_name/and/folder_path/redacted"
EXTENSION = 'txt'
# Parse out a date from each filename, print per-day line counts
Dir["#{PATH}/*.#{EXTENSION}"].each do |log_file|
return_value = ''
@dpritchett
dpritchett / durstenfeld_shuffle.coffee
Created May 6, 2011 16:30
durstenfeld array shuffle in coffeescript
# See http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
# written as one-liners because my REPL didn't like multiline functions this morning
# tested on CoffeeScript v1.0.1
input = [0 .. 7]
swap = (input, x, y) -> [input[x], input[y]] = [input[y], input[x]]
rand = (x) -> Math.floor(Math.random() * x)
durst = (input) -> swap(input, i, rand(i)) for i in [input.length - 1 .. 1]
"""