Skip to content

Instantly share code, notes, and snippets.

@sjaveed
sjaveed / gist:7765208
Created December 3, 2013 07:13
Declaring Private Methods on on a Specific Instance of a Class in Ruby
class Person
def name
nickname? ? 'Bob' : 'Robert'
end
def nickname?
false
end
end
# Setup HTML::WhiteListSanitizer
ActionView::Base.sanitized_allowed_attributes.add('style')
%w/margin padding padding-left padding-right padding-top padding-bottom list-style/.each do |prop|
ActionView::Base.sanitized_allowed_css_properties.add(prop)
end
original_string = %Q|<h1 style="color: #333 !important; font-family: arial !important; font-size: 45px !important; font-style: normal !important; font-weight: normal !important; margin: 0 0 10px 0 !important; line-height:-0.5px !important;">Test heading;<a href="https://www.google.com" style="color: #F3724E   !important; font-family: arial !important; text-decoration: none !important;"> link text</a>&nbsp;:&nbsp;</h1>|
sanitized_string = ActionView::Base.white_list_sanitizer.sanitize(original_string)
@sjaveed
sjaveed / game.rb
Last active August 29, 2015 14:24
class Game < ActiveRecord::Base
belongs_to :schedule
belongs_to :contestant_a, polymorphic: true
belongs_to :contestant_b, polymorphic: true
has_one :score, dependent: :destroy
def winner
score.winner
@sjaveed
sjaveed / GIF-Screencast-OSX.md
Created June 1, 2017 20:23 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@sjaveed
sjaveed / cluster_colors.rb
Created September 25, 2017 22:16
Clustering Colors using Affinity Propagation
#!/usr/bin/env ruby
require 'bundler/setup'
require 'affinity_propagation'
require 'byebug'
module AffinityPropagation
class Calculator
attr_accessor :availabilities, :responsibilities, :similarities
end
end
@sjaveed
sjaveed / .bash_profile
Created November 1, 2017 14:30
bash helper functions for docker
###
# Docker-related functions and aliases
###
# Include these into your ~/.bash_profile; don't replace your ~/.bash_profile with this
alias dc="docker-compose"
alias dcr="docker-compose run --rm"
alias dce="docker-compose exec"
@sjaveed
sjaveed / gist:22426672f799f58c9d7c5850b3f1da45
Created March 18, 2019 01:47 — forked from jimbojsb/gist:1630790
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2: