Skip to content

Instantly share code, notes, and snippets.

@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
@solotimes
solotimes / deploy.rb
Created May 18, 2011 14:28
the deploy task script
#!/usr/bin/env ruby
require "rubygems" # ruby1.9 doesn't "require" it though
require "thor"
require "yaml"
class Deploy < Thor
include Thor::Actions
desc "init","create a local site"
def init
#domain = safe_ask("Deploy domain",options[:domain])
##
# 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 / juggernaut.conf
Created October 27, 2011 08:22
juggernaut upstart script
description "juggernaut"
author "andrew [email protected]"
# must be start after redis-server
start on started redis-server
stop on stopped redis-server
# Automatically Respawn:
respawn
respawn limit 99 5
@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
@solotimes
solotimes / README.md
Created April 4, 2012 15:53
sudulog

1.系统需求

  • Ubuntu 10.10 (以下默认为使用此发布版Linux,其他版本方法类似)

  • Git

    参考安装方法:

      add-apt-repository "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen"
      apt-get update 
    

apt-get install mongodb-10gen

@solotimes
solotimes / nginx.conf
Created April 9, 2012 07:29
nginx init conf
# nginx
description "nginx http daemon"
author "George Shammas <[email protected]>"
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
env DAEMON=/opt/nginx/sbin/nginx
env PID=/var/run/nginx.pid
@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 / Rails_new_todo.md
Created April 24, 2012 06:14
Rails new todo