Skip to content

Instantly share code, notes, and snippets.

View seabre's full-sized avatar

Sean Brewer seabre

  • CrowdFiber
  • Chattanooga, TN
View GitHub Profile
@seabre
seabre / replace_text_in_all_files.sh
Created September 16, 2011 17:26
Find and Replace Text in All Files Within a Directory Tree
find . -type f -print0 | xargs -0 sed -i 's/oldword/newword/g'
@seabre
seabre / foxtrot.py
Created September 16, 2011 17:32
Solve The Code From The FoxTrot Comic From 04/19/2009
#Originally from: http://codepad.org/nkoCRTss
#Solve the code from today's (04/19/2009) FoxTrot comic.
#**NOT** the best (definitely not the most elegant) way to do this, but I banged it out in 5 minutes...
from math import *
code = [16,11,13,5,10,2,15,18,13,23,8,11,17,11,12,22,11,12,19]
def solve(num):
@seabre
seabre / fizzbuzz.py
Created September 16, 2011 17:35
Extremely Obnoxious FizzBuzz
#Originally from: http://codepad.org/9Gl9VQ0u
#Extremely obnoxious Python solution to FizzBuzz
#http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html
import sys
map(lambda i: sys.stdout.write("FizzBuzz\n") if i%15==0 else (sys.stdout.write("Fizz\n") if i%3==0 else (sys.stdout.write("Buzz\n") if i%5==0 else sys.stdout.write(str(i)+"\n"))), range(1,101))
@seabre
seabre / one_month_ahead.rb
Created September 16, 2011 18:21
Get Datetime in the Currently Set Timezone in Rails for the Beginning of the Next Month
#Get datetime for the beginning of the next month in the timezone that's currently set.
one_month_ahead = Time.zone.now.at_beginning_of_month.next_month
#You can format the datetime the way you want as well.
one_month_ahead = Time.zone.now.at_beginning_of_month.next_month.strftime("%Y-%m-%d %T %z")
@seabre
seabre / random_password.js
Created September 19, 2011 21:21
Random Password Generator (Bookmarklet Version)
(function(){var a=[["0","1","2","3","4","5","6","7","8","9"],["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]];pass="";for(var b=8;b>0;b--){var c=a[Math.floor(Math.random()*a.length)];pass+=c[Math.floor(Math.random()*c.length)]}prompt("Random Password:",pass)})();
@seabre
seabre / file_permission_octal.sh
Created September 21, 2011 16:15
Easily Show File Permission Octal for a File
stat -c '%a' myfile
@seabre
seabre / get_columns_for_rails_admin.rb
Created September 30, 2011 17:02
Get Columns From Table Formatted For Configuration in Rails Admin
Model.columns.map {|c| puts "field :#{c.name}"}
@seabre
seabre / sketch_template.pde
Created October 12, 2011 16:11
Basic Processing Sketch Template
int x,y;
void setup() {
x = 0;
y = 0;
size(640,480); // size of the window in pixels
frameRate(30); // call the draw() @ 30 fps
background(0,0,0); // background color
@seabre
seabre / hexagon.pde
Created October 14, 2011 15:24
Drawing a Hexagon in Processing
void hexagon(int x, int y, int edge_length) {
float c = (float) edge_length;
float a = .5 * c;
float b = sin(radians(60)) * c;
float xf = (float) x;
float yf = (float) y;
/* Fill with a color of your choice. */
fill(0,174,239);
@seabre
seabre / rgb_conversions.js
Created October 15, 2011 02:01
RGB Conversions
/*
rgb_hex_to_rgb_list
Example input:
rgb_hex_to_rgb_list("ffffff");
Output:
[255,255,255]