Skip to content

Instantly share code, notes, and snippets.

View wxianfeng's full-sized avatar
🎯
Focusing

xianfeng wang wxianfeng

🎯
Focusing
View GitHub Profile
@tansengming
tansengming / Rails Console Actionmailer test.rb
Created April 24, 2009 15:14
Rails Console Actionmailer test
# Copy and paste this to the rails console to test your email settings
class MyMailer < ActionMailer::Base
def test_email
@recipients = "someone@somewhere.com"
@from = "must_be_same_as_smpt_account_login@gmail.com"
@subject = "test from the Rails Console"
@body = "This is a test email"
end
end
require 'rubygems'
require 'RMagick'
include Magick
PIXEL = ["&", "8", "0", "$", "2", "1", "|", ";", ":", "'", " ", " "]
colors = PIXEL.size - 1.0
# load image
oimg = ImageList.new("mario.jpg")
@pcreux
pcreux / runner.rb
Created May 20, 2010 00:11
script/runner for Rails 3
#!/usr/bin/env ruby
# script/runner for rails 3.0
APP_PATH = File.expand_path('../../config/environment', __FILE__)
require 'rubygems'
require 'rails/commands/runner'
# If you post to a Ruby on Rails REST API endpoint, then you'll get an
# InvalidAuthenticityToken exception unless you set a different
# content type in the request headers, since any post from a form must
# contain an authenticity token.
#
# This example shows you how to post to a rails endpoint.
require 'json'
@HenrikJoreteg
HenrikJoreteg / JS Util solution using underscore.js
Created October 22, 2010 21:20
Rather than creating some other util global, just extend underscore.js with any additional methods you want.
// If you don't use underscore.js, use it (http://documentcloud.github.com/underscore/)
// Then, use underscore's mixin method to extend it with all your other utility methods
// like so:
_.mixin({
escapeHtml: function () {
return this.replace(/&/g,'&amp;')
.replace(/>/g,'&gt;')
.replace(/</g,'&lt;')
.replace(/"/g,'&quot;')
.replace(/'/g,'&#39;');
@rguggemos
rguggemos / Kaminari ajax pager
Created March 18, 2011 17:33
Kaminari ajax pager
If you switch to kaminari,
http://railscasts.com/episodes/254-pagination-with-kaminari
...the lines added to application.js become redundant when you implement the pager like in this demo project:
https://github.com/amatsuda/kaminari_example/tree/ajax
in index.html:
@jokester
jokester / [程序向]如何得到所有组合结果.rb
Created August 13, 2011 11:49
求数组{ (0..N1),{0..N2},...,(0..Nn) }的笛卡尔积
#!/usr/bin/ruby
puts "input N"
i=gets.to_i
m=[1]
1.upto i do |j|
puts "input N#{j}"
k=gets.to_i
m.unshift m[0]*(k+1)
@huacnlee
huacnlee / will_paginate.js
Created August 24, 2011 01:41
使 WillPaginate 支持用左右键翻页
// Keyboard shortcuts for browsing pages of lists
(function($) {
$(document).keydown(handleKey);
function handleKey(e) {
var left_arrow = 37;
var right_arrow = 39;
if (e.target.nodeName == 'BODY' || e.target.nodeName == 'HTML') {
if (!e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) {
var code = e.which;
@biti
biti / deploy.rb
Created September 11, 2011 02:47
自动部署脚本
# auto deploy script
# content: sync update all servers code, control unicorn servers and thin servers
# by liuzihua
default_environment["LC_CTYPE"] = "en_US.UTF-8"
# servers!
set :server1, "124.42.34.226"
set :server2, "124.42.34.238"
set :server3, "119.254.7.196"
@JoeyButler
JoeyButler / chat.html
Created October 24, 2011 00:14
Simple Chat app
<!DOCTYPE html>
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js'></script>
<script>
$(document).ready(function(){
function debug(str){ $("#debug").append("<p>"+str+"</p>"); };
if(typeof WebSocket === 'undefined') {
alert("Your browser does not support websockets.")
}