Skip to content

Instantly share code, notes, and snippets.

View xwmx's full-sized avatar

William Melody xwmx

View GitHub Profile
@xwmx
xwmx / gist:2951957
Created June 19, 2012 02:21
git aliases
#==========================================================================
# Git aliases
#==========================================================================
alias g='git'
alias gb='git branch'
alias gba='git branch -a'
alias gstat='git status'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gd='git diff | mate'
@xwmx
xwmx / Japanese style
Last active October 1, 2015 13:08 — forked from endolith/Has weird right-to-left characters.txt
Unicode smileys emoticons
⨀_⨀
⨂_⨂
(/◔ ◡ ◔)/
°ﺑ°
(¬_¬)
(´・ω・`)
(ʘ_ʘ)
(ʘ‿ʘ)
(๏̯͡๏ )
(◕_◕)
@xwmx
xwmx / kindlestrip.py
Created August 18, 2011 19:36
kindlestrip.py: for removing unnecessary portions of .mobi/.prc kindle files created with kindlegen
#!/usr/bin/python
#
# This is a python script. You need a Python interpreter to run it.
# For example, ActiveState Python, which exists for windows.
#
# This script strips the penultimate record from a Mobipocket file.
# This is useful because the current KindleGen add a compressed copy
# of the source files used in this record, making the ebook produced
# about twice as big as it needs to be.
#
@xwmx
xwmx / .bashrc
Created July 31, 2011 16:33
utc_timestamp
alias utc_timestamp='date -u "+%Y%m%d%H%M%S"'
@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
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 / 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 */")
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!"
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
# 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