This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Nil(object): | |
def __getitem__(self, key): | |
return Nil() | |
def __nonzero__(self): | |
return False | |
class NestedDict(dict): | |
def __init__(self, *args, **kwargs): | |
self.update(*args, **kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveSupport | |
class TimeWithZone | |
alias_method :to_int, :to_i # For some reason this is requires after upgrading to ruby 1.9.3-p429 - https://github.com/rails/rails/pull/10686 | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brew install sbt | |
cd /tmp | |
wget http://apache.spd.co.il/kafka/0.8.0/kafka_2.8.0-0.8.0.tar.gz | |
tar -zxvf kafka_2.8.0-0.8.0.tar.gz -C /usr/local/ | |
cd /usr/local/kafka_2.8.0-0.8.0 | |
sbt update | |
sbt package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int rLED = 11; | |
const int gLED = 9; | |
const int bLED = 10; | |
const int sensor = A0; | |
const float minTemp = 10.0; | |
const float maxTemp = 50.0; | |
int redV = 0; | |
int greenV = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Concerns | |
module CreatedAtScopes | |
extend ActiveSupport::Concern | |
included do | |
%w(created_at updated_at).each do |prop| | |
verb = prop.gsub('_at', '') | |
scope "#{verb}_last_h", lambda { where("#{prop} >= ?", (Time.now-1.hour).to_s(:db)) } | |
scope "#{verb}_last_6h", lambda { where("#{prop} >= ?", (Time.now-6.hour).to_s(:db)) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CanAccessSomeGem | |
def self.matches?(request) | |
current_user = request.env['warden'].user | |
return false if current_user.blank? | |
return < some condition on current_user > | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
has_many :subscriptions_members, | |
:class_name => "Subscription", | |
:conditions => {:kind => Subscription::SubscriptionKinds::MEMBER}, | |
:dependent => :destroy | |
has_many :subscriptions_followers, | |
:class_name => "Subscription", | |
:conditions => {:kind => Subscription::SubscriptionKinds::FOLLOWER}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This function cleans up messy HTML that was pasted by a user to a WYSIWYG editor. | |
# Specifically it also handles messy Word\Outlook generated HTML while keeping its original formattings. | |
require 'rubygems' | |
require 'sanitize' | |
def clean_up_document(html) | |
elements = %w[p b h1 h2 h3 h4 h5 h6 strong li ul ol i br div pre p] | |
attributes = { | |
'a' => ['href', 'title'], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RssResult : FileResult | |
{ | |
private readonly SyndicationFeed _feed; | |
/// <summary> | |
/// Creates a new instance of RssResult | |
/// </summary> | |
/// <param name="feed">The feed to return the user.</param> | |
public RssResult(SyndicationFeed feed) | |
: base("application/rss+xml") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_git_branch () { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
} | |
RED="\[\033[0;31m\]" | |
YELLOW="\[\033[0;33m\]" | |
GREEN="\[\033[0;32m\]" | |
NO_COLOUR="\[\033[0m\]" | |
PS1="$GREEN\u@machine$NO_COLOUR:\w$YELLOW\$(parse_git_branch)$NO_COLOUR\$ " |
NewerOlder