Skip to content

Instantly share code, notes, and snippets.

# http://gist.github.com/16885
# $ ./script/console
# Loading development environment (Rails 2.1.0)
# >>
# >> User.whatis :create!
# File: /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/validations.rb:876
# 872: end
# 873:
# 874: # Creates an object just like Base.create but calls save! instead of save
@juggy
juggy / gist:1023110
Created June 13, 2011 16:25
Revert to last saved version using Backbone.js
Skepic.EventedModel = Backbone.Model.extend
initialize: ->
Backbone.Model.prototype.initialize.apply(@, arguments)
_.bindAll(@, "mark_to_revert", "revert")
@mark_to_revert()
save : (attrs, options)->
self = this
options || (options = {})
@benedikt
benedikt / rails.rb
Created July 30, 2011 13:16
Capistrano task to open a rails console on a remote server. Require this file in your deploy.rb and run "cap rails:console"
# encoding: UTF-8
Capistrano::Configuration.instance(:must_exist).load do
namespace :rails do
desc "Open the rails console on one of the remote servers"
task :console, :roles => :app do
hostname = find_servers_for_task(current_task).first
exec "ssh -l #{user} #{hostname} -t 'source ~/.profile && #{current_path}/script/rails c #{rails_env}'"
end
end
@bentruyman
bentruyman / Custom.css
Created August 22, 2011 19:35
Tomorrow Theme for Chrome Developer Tools
/**********************************************/
/*
/* Tomorrow Skin by Ben Truyman - 2011
/*
/* Based on Chris Kempson's Tomorrow Theme:
/* https://github.com/ChrisKempson/Tomorrow-Theme
/*
/* Inspired by Darcy Clarke's blog post:
/* http://darcyclarke.me/design/skin-your-chrome-inspector/
/*
@codeincontext
codeincontext / gist:1268425
Created October 6, 2011 19:41
iOS 5 tips and tricks

Note: you can find a more involved review of iOS5 here: http://modmyi.com/content/5532-ios-5-released-full-review.html

iOS 5 Quick Tips

So you've just upgraded your iPhone to the new version (iOS 5), this is a little post to help you get the most out of the new shiny features available to you.

  • Your phone will automatically sync over wifi when you're at home. You don't have to plug it in or wait for it to finish.

  • Messages to other iPhone and iPod touch users will now go over wifi if possible. These will come up in a different colour.

@codeincontext
codeincontext / gist:1285806
Last active January 25, 2023 17:05
Javascript function to show how long ago a timestamp was as a pretty string
function timeAgo(time){
var units = [
{ name: "second", limit: 60, in_seconds: 1 },
{ name: "minute", limit: 3600, in_seconds: 60 },
{ name: "hour", limit: 86400, in_seconds: 3600 },
{ name: "day", limit: 604800, in_seconds: 86400 },
{ name: "week", limit: 2629743, in_seconds: 604800 },
{ name: "month", limit: 31556926, in_seconds: 2629743 },
{ name: "year", limit: null, in_seconds: 31556926 }
];
@brentertz
brentertz / rvm2rbenv.txt
Created November 21, 2011 23:00
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@bga
bga / [fun] various forms of ternary operator in JavaScript.js
Created March 7, 2012 15:10
[fun] various forms of ternary operator in JavaScript
// add your variants of
a ? b : c
// in comments :)
// a is boolean
// b and c - any type
// lazy evaluation isnt important
@nijikokun
nijikokun / example-user.js
Created May 3, 2012 20:46
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9_-]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@sindresorhus
sindresorhus / blur-prank.user.js
Last active January 4, 2023 10:33
Blur prank UserScript
// ==UserScript==
// @name Dictionary
// @version 0.1
// @author Sindre Sorhus
// @include *
// ==/UserScript==
document.documentElement.style.webkitFilter='blur(0.5px)';