Skip to content

Instantly share code, notes, and snippets.

@ndarville
ndarville / business-models.md
Last active January 13, 2024 17:27
Business models based on the compiled list at http://news.ycombinator.com/item?id=4924647. I find the link very hard to browse, so I made a simple version in Markdown instead.

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google
@damien
damien / concerns-messagable_with_data.rb
Created July 12, 2012 23:06
Extending Mailboxer through Concerns
module Concerns
module MessagableWithData
extend ActiveSupport::Concern
included do
Message.class_eval do
has_many :message_data,
class_name: MessageData,
@jboner
jboner / latency.txt
Last active May 7, 2024 19:39
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@myronmarston
myronmarston / ways_to_use_vcr.rb
Created April 13, 2012 15:00
Ways to use VCR for a request made by a let block
# 1) Use VCR.use_cassette in your let block. This will use
# the cassette just for requests made by creating bar, not
# for anything else in your test.
let(:foo) { VCR.use_cassette("foo") { create(:bar) } }
it "uses foo" do
foo
end
# 2) Wrap the it block that uses #foo in VCR.use_cassette.
@gbissett
gbissett / minibuild.rb
Created March 18, 2012 08:13
a build server that is smaller and less capable than cijoe
require 'sinatra'
CODE_PATH = '/repo/lives/here'
RVM_COMMAND = '[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm'
UPDATE_COMMAND = 'git pull'
BUILD_COMMAND = 'bundle && rake db:migrate && rake'
def log(message='')
File.open('build.log', 'a') {|log| log.puts "#{Time.now.utc} #{message}" }
end
@oodavid
oodavid / README.md
Last active April 6, 2024 18:45 — forked from aronwoost/README.md
Deploy your site with git

Deploy your site with git

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
  • apache's home directory is /var/www/
@amalagaura
amalagaura / runme.sh
Created December 15, 2011 04:29
Commands to fix damn CRLF with rubymine saving in windows
# Remove everything from the index
git rm --cached -r .
# Re-add all the deleted files to the index
# You should get lots of messages like: "warning: CRLF will be replaced by LF in <file>."
git diff --cached --name-only -z | xargs -0 git add
# Commit
git commit -m "Fix CRLF"
@cpatni
cpatni / app.rb
Created November 21, 2011 22:39
unique calculation using redis
require 'sinatra'
require 'redis'
require 'json'
require 'date'
class String
def &(str)
result = ''
result.force_encoding("BINARY")
@gfontenot
gfontenot / gist:1203520
Created September 8, 2011 14:25
Get duration of a video file with Ruby and FFMpeg
def get_movie_duration video_file
# Run ffmpeg on the video, and do it silently
ffmpeg_output = `/usr/local/bin/ffmpeg -i "#{video_file}" 2>&1`
# Find the duration in the output, and force a return if it's found
/duration: ([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2})/i.match(ffmpeg_output) { |m| return m[1] }
# If it didn't get a match, something is wrong. Log the error
return "FFMPEG ERROR"
@fnichol
fnichol / README.md
Created March 12, 2011 20:52
Download a cacert.pem for RailsInstaller

Why?

There is a long standing issue in Ruby where the net/http library by default does not check the validity of an SSL certificate during a TLS handshake. Rather than deal with the underlying problem (a missing certificate authority, a self-signed certificate, etc.) one tends to see bad hacks everywhere. This can lead to problems down the road.

From what I can see the OpenSSL library that Rails Installer delivers has no certificate authorities defined. So, let's go fetch some from the curl website. And since this is for ruby, why don't we download and install the file with a ruby script?

Installation

The Ruby Way! (Fun)