Skip to content

Instantly share code, notes, and snippets.

@solotimes
solotimes / 0_reuse_code.js
Last active August 29, 2015 14:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@solotimes
solotimes / deploy.rb
Created December 28, 2013 11:23 — forked from jeronimo/deploy.rb
set :sync_directories, ["public/system/images"]
set :sync_backups, 3
set :db_file, "mongoid.yml"
set :db_drop, '--drop' # drop database (rewrites everything)
@solotimes
solotimes / nginx.conf
Created April 15, 2012 13:41 — forked from huacnlee/nginx.conf
Nginx http proxy cache to mirror of Rubygems.org
# 在本地服务器建立 rubygems.org 的镜像缓存,以提高 gem 的安装速度
# 此配置设置缓存过期为1天,也就是说,新上的 gem 无法马上安装
# 做这个起什么作用?
# rubygems 的很多资源文件是存放到 Amazon S3 上面的,由于 GFW 对某些 S3 服务器又连接重置或丢包,导致 gem 安装异常缓慢或有时候根本无法连接安装。
# 而通过这种跳板的方式可以很好的解决这个问题,当然前提是 Nginx反向代理 服务器需要在国外
proxy_cache_path /var/cache/rubygems levels=1:2 keys_zone=RUBYGEMS:10m
inactive=24h max_size=1g;
server {
listen 80;
@solotimes
solotimes / bootstrap_form_builder.rb
Created November 9, 2011 13:42 — forked from jamiepenney/bootstrap_form_builder.rb
Form builder for Twitter Bootstrap form elements.
#https://gist.github.com/1351456
#based on http://gist.github.com/1236567.git
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
def get_error_text(object, field, options)
if object.nil? || options[:hide_errors]
""
else
errors = object.errors[field.to_sym]
if errors.empty? then "" else errors.first end
##
# Calendar helper with proper events
# http://www.cuppadev.co.uk/webdev/making-a-real-calendar-in-rails/
#
# (C) 2009 James S Urquhart (jamesu at gmail dot com)
# Derived from calendar_helper
# (C) Jeremy Voorhis, Geoffrey Grosenbach, Jarkko Laine, Tom Armitage, Bryan Larsen
# Licensed under MIT. http://www.opensource.org/licenses/mit-license.php
##
@solotimes
solotimes / mongoid_cached_document.rb
Created May 12, 2011 03:01
Some Mongoid extensions I made, to be moved to a repository soon (with tests etc..)
module Mongoid
# Caches the entire document in a Marshall and Redis.
# Defines Document#get(id), adds methods to recache document after a save.
# Add `include Mongoid::CachedDocument` in your model to enable the feature.
module CachedDocument
def self.included(base)
base.class_eval do
include InstanceMethods
extend ClassMethods
before_save :refresh_cache