Skip to content

Instantly share code, notes, and snippets.

View alistairholt's full-sized avatar

Alistair Holt alistairholt

View GitHub Profile
@alistairholt
alistairholt / boolean_value.rb
Created November 7, 2018 11:32 — forked from attenzione/boolean_value.rb
Ruby: casting to boolean value
class BooleanValue
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/column.rb#L8
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF']
def self.from_string(value)
Rails.present? ? with_rails(value) : without_rails(value)
end
private
### Keybase proof
I hereby claim:
* I am alistairholt on github.
* I am alistairholt (https://keybase.io/alistairholt) on keybase.
* I have a public key whose fingerprint is 5864 8D16 40D9 BB22 BD78 6702 B27D 505C 5E6A 44B7
To claim this, I am signing this object:
@alistairholt
alistairholt / pdrop.sh
Created October 25, 2013 16:53
Rails & Postgres: Better dropping of the database – https://coderwall.com/p/qtkppg
pgdrop() {
RAILS_ENV=$1
: ${RAILS_ENV:="development"}
RUBY_SCRIPT=$(cat <<SCRIPT
db_config_path = File.expand_path("config/database.yml", Dir.getwd)
abort 'NO_CONFIG' unless File.exists?(db_config_path)
db_config = YAML.load(File.open(db_config_path))["$RAILS_ENV"]
abort 'NO_POSTGRES' unless db_config["adapter"] == "postgresql"
abort db_config["database"]
SCRIPT)
# Example: UIPanGestureRecognizer on a single UIView
class FooViewController < UIViewController
def loadView
# View
self.view = UIView.alloc.init
# Block
blockFrame = CGRectMake(100,100,100,100)
block = UIView.alloc.initWithFrame(blockFrame)
@alistairholt
alistairholt / flexible-box.css
Created March 22, 2013 11:21
An example of CSS Flexible Box in early 2013
#foo {
display: -webkit-box;
display: -moz-box;
display: -ms-box;
display: -webkit-flex;
display: box;
display: flex;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
-o-box-orient: vertical;
$(function () {
$.jribbble.getShotsByPlayerId('ryanAmurphy', function (playerShots) {
var html = '';
$.each(playerShots.shots, function (i, shot) {
html += '<li><h3>' + shot.title + '</h3>';
html += '<h4>by ' + shot.player.name + '</h4><a href="' + shot.url + '">';
html += '<img src="' + shot.image_teaser_url + '" ';
html += 'alt="' + shot.title + '"></a></li>';
});
@alistairholt
alistairholt / gist:918011
Created April 13, 2011 17:51
CSS Development in 2011
#foo {
background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(#EFF6F5), color-stop(0.02, #C6E2DF), color-stop(0.5, #C6E2DF), color-stop(0.98, #C6E2DF), to(#EFF6F5));
background: -webkit-linear-gradient(0deg, #EFF6F5, #C6E2DF 2%, #C6E2DF 50%, #C6E2DF 98%, #EFF6F5);
background: -moz-linear-gradient(0deg, #EFF6F5, #C6E2DF 2%, #C6E2DF 50%, #C6E2DF 98%, #EFF6F5);
background: -o-linear-gradient(0deg, #EFF6F5, #C6E2DF 2%, #C6E2DF 50%, #C6E2DF 98%, #EFF6F5);
background: linear-gradient(0deg, #EFF6F5, #C6E2DF 2%, #C6E2DF 50%, #C6E2DF 98%, #EFF6F5);
}
Process: CoverSutra [2946]
Path: /Applications/CoverSutra.app/Contents/MacOS/CoverSutra
Identifier: com.sophiestication.CoverSutra
Version: 2.2 Beta 6 (220b6)
Code Type: X86-64 (Native)
Parent Process: launchd [298]
Date/Time: 2009-09-20 20:46:50.608 +0100
OS Version: Mac OS X 10.6.1 (10B504)
Report Version: 6
Process: CoverSutra [2946]
Path: /Applications/CoverSutra.app/Contents/MacOS/CoverSutra
Identifier: com.sophiestication.CoverSutra
Version: 2.2 Beta 6 (220b6)
Code Type: X86-64 (Native)
Parent Process: launchd [298]
Date/Time: 2009-09-20 20:46:50.608 +0100
OS Version: Mac OS X 10.6.1 (10B504)
Report Version: 6
/!\ FAILSAFE /!\ Sat Aug 15 16:09:30 +0100 2009
Status: 500 Internal Server Error
Invalid JSON string
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/json/backends/yaml.rb:18:in `decode'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/json/decoding.rb:11:in `__send__'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/json/decoding.rb:11:in `decode'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/params_parser.rb:42:in `parse_formatted_parameters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/params_parser.rb:11:in `call'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/session/cookie_store.rb:93:in `call'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/reloader.rb:29:in `call'