Skip to content

Instantly share code, notes, and snippets.

class Assignment < ActiveRecord::Base
belongs_to :project
belongs_to :user
validates_uniqueness_of :project_id, :scope => :user_id
before_create :calculate_time_allocation
def calculate_time_allocation
self.time_allocation ||= (100 - user.reload.total_time_allocation)

Sure, I had been a telemarketer, a strawberry picker, a caterer and an employee of Dairy Queen. But on January 1st of 2009 I got my first “real” job.

I was hired by StudioCT, a web design and development shop run through The Ohio State University Honors and Scholars program StudioCT is managed by David McIntyre and Ray Arebalo. Thanks to them, I gained my first real web programming experience. Up until that point my only familiarity with web programming had come from taking a few of the classes offered by the Media, Marketing and Communications Scholars Program. I played around with .Net 2.0 using C# under the much appreciated guidance of Jimmy Lauzau, scattering in some php with Anish Minstry. However, my results were only of moderate success, which was discouraging. Working at studioCT quickly changed this, as I was put on real projects and assigned to work with students who had quite a bit more experience than I had

@tonywok
tonywok / gist:802531
Created January 30, 2011 04:25
simple search
scope :search, lambda { |keywords|
query = nil
table = arel_table
SEARCH_ATTRS.each do |attr|
if attr == SEARCH_ATTRS.first
query = table[attr].matches("%#{keywords}%")
else
query = query.or(table[attr].matches("%#{keywords}%"))
end
end; where(query)
@tonywok
tonywok / results.md
Created September 15, 2011 01:33
Rails 3.1 Callbacks
s = Test.new(:name => "foo")

# ActiveRecord::Test after_initialize
# ActiveRecord::Test after_initialize, :on => :update
# ActiveRecord::Test after_initialize, :on => :create
# ActiveRecord::TestObserver after_initialize

# ===> #<Test id: nil, name: "foo", created_at: nil, updated_at: nil>
@tonywok
tonywok / ios-test.css
Created October 19, 2011 19:08
iOS Media Queries
// iOS Media Queries
// Goal: capture styles for iPhone, iPhone 3G, iPhone 3GS, iPhone 4, iPhone 4S, iPad, and iPad 2
//
// Author: Tony Schneider (@tonywok)
// Please tell me where I fail. :)
// iPhone v(4,4S) portrait
// test: black text (overwritten by v* portrait) with blue background
@media all and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait) {
a {
@tonywok
tonywok / gist:1838855
Created February 15, 2012 20:40 — forked from mattyoho/gist:1838553
Installing ruby-debug with ruby-1.9.3-p0
# Install with:
# bash < <(curl -L https://raw.github.com/gist/1333785)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with ruby-1.9.3-p0 ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem

ZMQ Notes

Basic Patterns

  • Request/Reply
  • Pub/Sub
  • Pipleline

Request Reply

@tonywok
tonywok / Hide Mobile Browser Chrome
Created April 27, 2012 17:39
Normalized hide address bar for iOS & Android on page load and orientation change
/*
* Normalized hide address bar for iOS & Android
* (c) Scott Jehl, scottjehl.com
*
* Modified by
* (c) Tony Schneider
*
* MIT License
*/
(function( win ){
@tonywok
tonywok / gist:8838149
Last active October 13, 2015 23:13
render raw json rails4/postgresql

So you need to store some JSON blobs in your database. What do you do? You have plenty of options these days. You can serialize a hash into the database. You can reach for a document store like mongodb. Or, you can lean on rails 4 postgres json data type support.

If you haven't yet upgraded to rails 4, go ahead and do that now, I'll wait...

tick, tock, looks at watch

Jokes aside, it's totally worth it.

Anywho, now that we are on rails 4, let's go ahead and stuff some JSON into the database.

@tonywok
tonywok / .bash_profile
Last active December 20, 2015 21:39
Simple little bash script for a decent bash prompt
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
GREEN="\033[0;32m"
CYAN="\033[0;36m"
BLUE="\033[0;34m"
RED="\033[0;31m"
RESET="\033[0m"