Skip to content

Instantly share code, notes, and snippets.

View wxianfeng's full-sized avatar
🎯
Focusing

xianfeng wang wxianfeng

🎯
Focusing
View GitHub Profile
@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'
@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"
@KensoDev
KensoDev / gist:1323028
Created October 28, 2011 18:42
Re-queue all failed workers to the original queue, remove the failed item
task :requeue_failed do
(Resque::Failure.count-1).downto(0).each do |i|
Resque::Failure.requeue(i)
Resque::Failure.remove(i)
end
end
@pjb3
pjb3 / irb_output.txt
Created October 1, 2013 00:21
Rails 4 appears to log SQL queries in the console in development by default. If it doesn't, I can't figure out why it is for me.
$ cat ~/.irbrc
cat: /Users/pbarry/.irbrc: No such file or directory
$ rails c
Loading development environment (Rails 4.0.0)
irb(main):001:0> Subscription.first
Subscription Load (2.5ms) SELECT "subscriptions".* FROM "subscriptions" ORDER BY "subscriptions"."id" ASC LIMIT 1
=> nil
irb(main):002:0> puts ENV.keys.sort
Apple_PubSub_Socket_Render
Apple_Ubiquity_Message
@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:
@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.")
}
@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;');
@xiangst0816
xiangst0816 / imgCenter.html
Last active June 3, 2018 08:51
将不同大小的img放在固定大小的div中; 要求img不能被拉伸覆盖、要水平居中放置在中间; 如果图片高度超出容器,则以高度为基准确定宽度,反之亦然; img不固定大小设置为inline,外层用line-height和text-align:center确定水平垂直居中;
<a href="">
<div class="cbCoorBox_e">
<img src="img/index/hanya.png" alt="合作机构">
</div>
</a>