Skip to content

Instantly share code, notes, and snippets.

View elado's full-sized avatar
👨‍💻

Elad Ossadon elado

👨‍💻
View GitHub Profile
@elado
elado / gist:979577
Created May 18, 2011 21:14
Blocks with closures errors in Obj-C
@interface TestClass : NSObject {
#if NS_BLOCKS_AVAILABLE
void (^blk)(void);
#endif
}
- (id)initWithBlock:(void (^)(void))block;
- (void)exec;
@end
@implementation TestClass
@elado
elado / Rakefile
Created May 21, 2011 18:13
Fix Rails with Rake 0.9
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake'
################################
# fixes rake 0.9 bug w/ rails
################################
module ::RailsAppNameHere
@elado
elado / gist:1004030
Created June 2, 2011 06:40
Date Regexp Validator
^((29\/0?2(?=\/(\d{2}(0[48]|[13579][26]|[2468][048])|
([13579][26]|[2468][048])00))|([01]?\d|2[0-8])\/(0?\d|1[0-2])|
(29|30)\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/\d{4})$
@elado
elado / gist:1171075
Created August 25, 2011 16:24
Turn off logging in Obj-C
#define GB_ALLOW_LOG 1
#if GB_ALLOW_LOG
#define GB_LOG(fmt, ...) NSLog(fmt, ##__VA_ARGS__)
#else
#define GB_LOG(fmt, ...)
#endif
@elado
elado / convert_ruby_hash_syntax_to_1.9.2.rb
Created December 13, 2011 07:44
Convert Entire Ruby Project Hash Syntax to 1.9 ( :sym => value to sym: value )
Dir['**/*.rb', '**/*.rake'].each { |f|
s = open(f).read
awesome_rx = /(?<!return)(?<!:)(?<!\w)(\s+):(\w+)\s*=>/
count = s.scan(awesome_rx).length
next if count.zero?
s.gsub!(awesome_rx, '\1\2:')
puts "#{count} replacements @ #{f}"
open(f, 'w') { |b| b << s }
}
@elado
elado / gist:3075358
Created July 9, 2012 09:38
Some Ruby Array methods
class Array
def pinject(memo, &block)
inject(memo) { |all, curr| block.call(all, curr); all }
end
def hash_by
return {} unless block_given?
pinject({}) { |all, curr|
# yield = block to extract key from an item
@elado
elado / open gem in sublime.sh
Last active December 11, 2015 16:28
Open/Edit a gem in Sublime Text.
# usage: ge devise
ge() {
gem=`bundle show $1`
if [[ "$gem" =~ ^/ ]];
then
echo "$gem"
`subl $gem`
else
echo "gem not found"
@elado
elado / SASS: 2x images for Retina or high DPI screens.scss
Last active December 16, 2015 03:59
Get retina mac/iPhone/iPad show the @2x image, with minimum hassle.
@mixin high_pixel_ratio {
@media screen and
(-webkit-min-device-pixel-ratio: 2),
(min--moz-device-pixel-ratio: 2),
(min-resolution: 2dppx),
(min-resolution: 192dpi) {
@content;
}
}
@elado
elado / ruby array order.rb
Last active December 17, 2015 11:59
Order / Limit an Array, like in SQL: array.order('score DESC, name').limit(3)
class Array
DESC_RX = /\s*desc$/i
ASC_DESC_RX = /\s*(?:asc|desc)$/i
def order(by)
by = by.split(',').map(&:strip)
sort do |a, b|
by_is_desc = by.map { |col| col =~ DESC_RX }
by_cols = by.map { |col| col.sub(ASC_DESC_RX, "") }
@elado
elado / app.js
Last active December 31, 2015 06:29
Simple, multi environment config with Node.js
// app.js
var config = require("config/app");
console.log(config.dbProvider);