Skip to content

Instantly share code, notes, and snippets.

View xwmx's full-sized avatar

William Melody xwmx

View GitHub Profile
#!/usr/bin/env python
# Name generating code
# Copyright (c) 2010 Ninite.com
#
# Released into the public domain - enjoy!
#
# Story at http://blog.ninite.com/post/620277259/how-ninite-was-named-by-a-computer-program
from datetime import datetime, date
Norman Schur's 1000 Most Important Words
This is Norman Schur's list of the 1,000 "most important" words. There are actually 1,019 here because of those that are similarly spelled, opposites of one another, etc. I've gone through and marked with asterisks the ones (*) that I'm somewhat uncomfortable with (177 of these), as in I'd be slightly apprehensive if you challenged me to pinpoint their meaning, and the ones (**) that I'm basically clueless about (26 of these). I feel roughly fluent with the rest.
abashed
*abate
abdicate
aberrant
abominate
abrasive
abrogate
defaults: &defaults
adapter: postgresql
encoding: utf8
username: username
password: password
host: localhost
pool: 10
development:
database: application_name_development
# http://daringfireball.net/2010/07/improved_regex_for_matching_urls
(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
# http://news.ycombinator.com/item?id=1571894
# A quick tips when creating block DSLs in Ruby:
def search(&blk)
if blk.arity == 1
blk.call(self)
else
self.instance_eval(&blk)
end
end
class DashboardController < ApplicationController
before_filter :require_user
def index
@feed_items = FeedItem.followed_by(current_user.id).
includes(:post).paginate(:page => params[:page])
@page_title = "#{APP_CONFIG['site_name']} | Dashboard"
end
end
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
@xwmx
xwmx / gist:850321
Created March 2, 2011 02:01
destroy_data.rb
def destroy_data
puts "== Data: Destroying all data ".ljust(79, "=")
sql = ActiveRecord::Base.connection()
sql.execute "SET autocommit=0"
sql.begin_db_transaction
if sql.adapter_name == "MySQL"
sql.execute("/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */")
sql.execute("/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */")
module GoogleAnalyticsHelper
def google_analytics_for(account, domain)
unless account.blank?
<<-ANALYTICS
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '#{account}']);
_gaq.push(['_setDomainName', '#{domain}']);
_gaq.push(['_trackPageview']);
@xwmx
xwmx / topic.rb
Created June 27, 2011 00:18 — forked from xdite/topic.rb
before_update :update_ranking
def self.calculate_ranking(score, created_at)
order = Math.log10(([score.abs,1].max))
if score > 0
sign = 1
elsif score < 0
sign = -1