Skip to content

Instantly share code, notes, and snippets.

View linyiru's full-sized avatar
🐝

Lawrence Lin linyiru

🐝
View GitHub Profile
@linyiru
linyiru / Attachment_fu: How To Delete The Original File
Created September 15, 2008 03:22 — forked from ashchan/gist:7251
Attachment_fu: How To Delete The Original File
class Photo < ActiveRecord::Base
has_attachment options_for_attachment_fu
after_attachment_saved do |foto|
# delete original file for disk space saving
FileUtils.rm foto.full_filename if foto.parent.nil?
end
end
def self.find(*args)
if args.first.to_s == "random"
super(find(:first , :offset => (count * rand).to_i))
else
super
end
end
@linyiru
linyiru / ActiveRecord: named_scope.rb
Created September 15, 2008 03:42
ActiveRecord: ActiveRecord: named_scope
class User < ActiveRecord::Base
named_scope :active, :conditions => {:active => true}
named_scope :inactive, :conditions => {:active => false}
named_scope :recent, lambda { { :conditions => ['created_at > ?', 1.week.ago] } }
end
# Standard usage
User.active # same as User.find(:all, :conditions => {:active => true})
User.inactive # same as User.find(:all, :conditions => {:active => false})
User.recent # same as User.find(:all, :conditions => ['created_at > ?', 1.week.ago])
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
class ApplicationController < ActionController::Base

(This is the text of the keynote I gave at Startup Riot 2009. Will update when video becomes available.)

Hi everyone, I’m Chris Wanstrath, and I’m one of the co-founders of GitHub.

GitHub, if you haven’t heard of it, has been described as “Facebook for developers.” Which is great when talking about GitHub as a website, but not so great when describing GitHub as a business. In fact, I think we’re the polar opposite of Facebook as a business: we’re small, never took investment, and actually make money. Some have even called us successful.

Which I’ve always wondered about. Success is very vague, right? Probably even relative. How do you define it?

After thinking for a while I came up with two criteria. The first is profitability. We employ four people full time, one person part time, have thousands of paying customers, and are still growing. In fact, our rate of growth is increasing – which means January was our best month so far, and February is looking pretty damn good.

Rails::Initializer.run do |config|
config.logger = Logger.new(STDOUT)
config.active_record.colorize_logging = false
#!/usr/bin/env perl -w
use strict;
use 5.010;
use Net::Twitter;
use DateTimeX::Easy;
use YAML;
my $username = $ARGV[0] || die "Give me an twitter username\n";
sub timecard_image_url {

HOWTO: iPhone AT&T Tethering

In 10 steps:

  • Update iTunes to 8.2 via Software Update
  • Update your iPhone to the 3.0 release (out today - June 17th)
  • Download this dmg and mount it: tethering file
  • Enable hidden carrier testing option (in Terminal.app): defaults write com.apple.iTunes carrier-testing -bool TRUE
  • Start up iTunes
require 'net/http'
require 'hpricot'
def rip_twitpic(url)
begin
code=url.match(/[\w]+$/).to_s
unless code.blank?
uri=URI.parse(url)
resp=Net::HTTP.get_response(uri)
html=Hpricot(resp.body)
@linyiru
linyiru / gist:194721
Created September 27, 2009 10:58
smtp_tls.rb
require "openssl"
require "net/smtp"
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
check_auth_args user, secret, authtype if user or secret
sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }