Skip to content

Instantly share code, notes, and snippets.

View somebox's full-sized avatar
⌨️
coding nights

Jeremy Seitz somebox

⌨️
coding nights
View GitHub Profile
@somebox
somebox / backup-mysql.sh
Created August 25, 2010 07:49
Simple script that backs up all MySQL user databases separately, with dated filenames
#!/bin/bash
# Dumps all databases to separate backup files named with today's date
BACKUP_TO="$HOME/backup/db"
MYSQLDUMP_OPTIONS="--compact --add-drop-table --skip-set-charset"
# ---
mkdir -p $BACKUP_TO
DATE=`date +'%Y-%m-%d'`
mysql -e 'show databases' | ruby -e "
@somebox
somebox / ruby memory usage
Created October 7, 2010 15:00
track down memory bloat
# Report how much memory is being used right now
# and call it from different places to debug:
def report_memory(note)
memory_usage = `ps -o rss= -p #{$$}`.to_i
mem_mb = sprintf('%.2f MB', memory_usage/1000.0)
puts "mem [#{note}]: #{mem_mb}"
end
@somebox
somebox / timezone.js
Created November 21, 2010 22:35
Get the user's timezone
// script by Josh Fraser (http://www.onlineaspect.com)
// modded by Jeremy Seitz to only return offset as integer
function calculate_time_zone() {
var rightNow = new Date();
var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0); // jan 1st
var june1 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
var temp = jan1.toGMTString();
var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
temp = june1.toGMTString();
@somebox
somebox / base_controller.rb
Created April 4, 2011 16:59
Authenticate in Rails with super-simple HTTP Auth.
class Admin::BaseController < ApplicationController
before_filter :authenticate
# ...
private
def authenticate
return true if Rails.env.development?
authenticate_or_request_with_http_basic do |id, password|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- example at http://somebox.com/canvas-fun.html -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/ocanvas/1.0/ocanvas.min.js"></script>
<title>Canvas Experiment</title>
<script type="text/javascript">
/*
@somebox
somebox / backbone.rails.js
Created June 30, 2011 00:59
Makes Backbone.js play nicely with default Rails setup
//
// Backbone.Rails.js
//
// Makes Backbone.js play nicely with the default Rails setup, i.e.,
// no need to set
// ActiveRecord::Base.include_root_in_json = false
// and build all of your models directly from `params` rather than
// `params[:model]`.
//
// Load this file after backbone.js and before your application JS.
@somebox
somebox / gist:1077974
Created July 12, 2011 13:25
DN Music App
The Democracy Now! music site will allow independent artists to submit original works for sharing with
other DN listeners, and potentially to be used as music on the show.
This is to be a standalone site, built in Rails 3. Users can fill out a form and upload a track.
After processing, they will receive and email containing a confirmation that the track was received,
and a link to the track on DN's site. By using this link, they can go to check for airplay, or
to request that a track be removed.
Home Page
Notices/Info/Events
@somebox
somebox / readme.md
Created September 26, 2011 06:05 — forked from metaskills/gist:756111
Rails 3 Models To Export Mephisto To Octopress & Disqus
require 'builder'
require 'digest/md5'
class Content < ActiveRecord::Base
belongs_to :user
end
class Section < ActiveRecord::Base
has_many :assigned_sections
has_many :articles, :order => 'position', :through => :assigned_sections
@somebox
somebox / nicer_ps1.sh
Created December 19, 2011 00:02
A nicer PS1
# A More Awesome PS1
# - only show username if its not the usual one
# - only show hostname if its not my local box (checks SSH_CONNECTION)
# - show root username in red
# - show current path, and smart truncate longer ones (>35 chars)
# - show git branch in brackets
# - show a red star for uncommitted git changes
# - show local hostname in green (192.*,10.*,::1)
# - show other hostnames in white
@somebox
somebox / unicorn.rb
Created March 7, 2012 08:19
unicorn.rb file to deal with dead processes/stale pid and knows about RVM
APP_ROOT = File.expand_path(File.dirname(File.dirname(__FILE__)))
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! APP_ROOT
rescue LoadError