Skip to content

Instantly share code, notes, and snippets.

@nepsilon
nepsilon / pip-mirror.md
Last active June 18, 2020 21:10
Use another mirror when PyPI go down — First published in fullweb.io issue #52

Use another mirror when PyPI go down

Find a mirror geographically close to you and use it like this:

pip install -i https://[mirror-url]/simple package

For instance, using a Beijing mirror:

pip install -i https://pypi.douban.com/simple package
@nightire
nightire / Changes in Rails 4_1.md
Last active May 11, 2022 04:50
拥抱 Rails 4 —— 详述 Rails 4 的新变化

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
@krypton
krypton / erb.sublime-snippet
Last active December 12, 2015 01:39
Sublime Text 2 snippet to create ERB tag
<!--
Inspired on Dr.Nic ruby-tmbundle (https://github.com/drnic/ruby-tmbundle/blob/master/Snippets/Insert%20ERb's%20%3C%25%20__%20%25%3E%20or%20%3C%25%3D%20__%20%25%3E.tmSnippet)
In your Sublime Text 2 User folder (Sublime Text 2/Packages/User), create this file and give a name "erb.sublime-snippet".
Than open a Ruby on Rails view file like HAML or ERB, type "erb" command and tab key.
This create ERB tag on your view file.
-->
<snippet>
<content><![CDATA[<%= ${0} %>]]></content>
<tabTrigger>erb</tabTrigger>
@wrburgess
wrburgess / README.md
Last active August 31, 2017 09:53
How to add a custom calculator for shipping or taxes to Spree
  1. Add initializer to config/application.rb
  2. Add new class to app/models/spree/calculators/[class_name].rb
  3. Add logic to class file

Class must have the following methods:

def self.description
  "Custom FlexiRate"
end
@demelziraptor
demelziraptor / add_devise_columns_to_user.rb
Created May 23, 2012 23:12
Devise API register and sign in using tokens
class AddDeviseColumnsToUser < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.string :authentication_token
end
end
def self.down
change_table :users do |t|
t.remove :authentication_token
end
@ktkaushik
ktkaushik / status_header_setter
Created April 17, 2012 11:32
Set HTTP status headers with respond_with( object ) in rails.
1xx Informational
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing
2xx Success
200 OK :ok
@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@aliang
aliang / Mac SSH Autocomplete
Created June 14, 2011 07:14
Add auto complete to your ssh, put into your .bash_profile
_complete_ssh_hosts ()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
grep -v ^# | \
uniq | \
grep -v "\[" ;
@parndt
parndt / gist:1011435
Created June 7, 2011 00:32
How to cache pages and clear them in Refinery CMS
# put in config/application.rb
config.to_prepare do
::PagesController.module_eval do
caches_page :show, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
caches_page :home, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
end
::Page.module_eval do
after_save :clear_static_caching!
after_destroy :clear_static_caching!