Skip to content

Instantly share code, notes, and snippets.

@paulnsorensen
paulnsorensen / foo.rb
Last active September 5, 2019 19:05
UPDATE: I have way better code that accomplishes this now at [https://github.com/paulnsorensen/lifesaver] Module to ease associated models that are indexed by tire. Use this to trigger reindexing instead of having to touch all the files.
#
# Please go to https://github.com/paulnsorensen/lifesaver
#
class Foo < ActiveRecord::Base
has_many :bars
belongs_to :baz
include IndexingHandler
indexed_associations :bars, :baz
end
  • 解压缩文件, 修正GBK编码
env LANG=GBK 7za x -olande "kepulande-r2  1.31.zip"
find . -exec convmv -f GBK -t utf8 --notest -r {} \;
  • 修改 import_image_libraries_for_kepulande.rake
  • 修改要导入的xls文件名
  • 修改解压缩的文件路径
@jakeonrails
jakeonrails / Ruby Notepad Bookmarklet
Created January 29, 2013 18:08
This bookmarklet gives you a code editor in your browser with a single click.
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
@sishen
sishen / unicorn
Created January 13, 2013 15:33
The unicorn init.d script to start/stop/restart the service
#!/bin/sh
set -u
set -e
# Feel free to change any of the following variables for your app:
export PATH=/usr/local/bin:$PATH
export HOME=/home/deploy
APP_ROOT=/var/www/pragmaticly/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
@bilus
bilus / gist:4367281
Last active December 10, 2015 02:28
Here's a slightly cleaned-up version that also supports Webkit. DISCLAIMER: It's based on the code above so it's supposed to work with Selenium & RackTest *but* I've only tested it against Webkit. It does not support the @announce tag.
module CookieStepHelper
class Cookies
def Cookies.for(session)
case session.driver
when Capybara::Driver::Selenium
SeleniumCookies.new(session.driver)
when Capybara::Driver::RackTest
RackTestCookies.new(session.driver)
when Capybara::Webkit::Driver
@alexjs
alexjs / cors-nginx.conf
Created November 28, 2012 22:42 — forked from michiel/cors-nginx.conf
Slightly tighter CORS config for nginx
#
# Slightly tighter CORS config for nginx
#
# A modification of https://gist.github.com/1064640/ to include a white-list of URLs
#
# Despite the W3C guidance suggesting that a list of origins can be passed as part of
# Access-Control-Allow-Origin headers, several browsers (well, at least Firefox)
# don't seem to play nicely with this.
#
@iwinux
iwinux / README.md
Created November 16, 2012 17:42
gotunnel on Android

Directory structure:

/data/gotunnel/
- gotunnel
- iptables
- redsocks/
-- config
-- redsocks
- start.sh
@sideshowcoder
sideshowcoder / ar_oauth2_example.rb
Created October 2, 2012 16:16
ActiveResource with OAuth2
class ProtectedResource < ActiveResource::Base
# since the gateway uses oauth2 every call needs to be authenticated,
# so the token for is needed
class << self
attr_accessor :token_string
end
# setup the headers for oauth2
def self.headers
{ 'authorization' => "Bearer #{token_string}"}
@hooopo
hooopo / README.markdown
Created August 8, 2012 14:12 — forked from greypants/README.markdown
RAILS 3: nav_link helper for adding 'selected' class to navigation elements

#Behold, the nav_link:

The nav_link helper works just like the standard Rails link_to helper, but adds a 'selected' class to your link (or its wrapper) if certain criteria are met. By default, if the link's destination url is the same url as the url of the current page, a default class of 'selected' is added to the link.

For full usage details, see: http://viget.com/extend/rails-selected-nav-link-helper

Drop nav_link_helper.rb into app/helpers in your Rails 3.x app and enjoy.

@karmi
karmi / active_record_associations.rb
Created July 29, 2012 16:57
An example of elasticsearch & Tire setup for ActiveRecord associations
# An example of elasticsearch & Tire setup for ActiveRecord associations.
#
# A `Book has_many :chapters` scenario, with mapping and JSON serialization
# for indexing associated models.
#
# Demonstrates three important caveats as of now:
#
# 1. You you have to use `touch: true` in the `belongs_to` declaration,
# to automatically notify the parent model about the update.
#