Skip to content

Instantly share code, notes, and snippets.

View nowlinuxing's full-sized avatar

Loose nowlinuxing

View GitHub Profile
@nowlinuxing
nowlinuxing / gist:b036a3b9913ded4dd35a
Created June 6, 2014 02:17
Install rmagick.gem on MacOSX
http://stackoverflow.com/questions/13963404/rails-and-os-x-how-to-install-rmagick
$ cd `Magick-config --prefix`/lib
$ for f in libMagick*-*.[0-9].dylib; do ln -s $f `echo $f | sed -e 's/-.*\.dylib/.dylib/'`; done
@nowlinuxing
nowlinuxing / README
Created May 8, 2014 02:51
Install libxml-ruby-2.3.3 @ Marvericks
I try to install libxml-ruby-2.3.3 at MacOSX Marvericks via gem (rbenv, Ruby-2.1.0), get below errors:
Building native extensions. This could take a while...
ERROR: Error installing libxml-ruby:
ERROR: Failed to build gem native extension.
/Users/***/.rbenv/versions/2.1.0/bin/ruby extconf.rb
extconf.rb:17:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
extconf.rb:17:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
checking for socket() in -lsocket... no
@nowlinuxing
nowlinuxing / gist:7307059
Created November 4, 2013 18:27
Use Twitter via API
# use twitter.gem earlier than 5.0.0
require "pp"
require "twitter"
# 1. Comment out oauth_token and oauth_token_secret.
# 2. Visit https://dev.twitter.com/apps/new. Get consumer_key and consumer_secret.
# 3. Execute.
# 4. Visit the Developper's site agein.
# 5. Go to "settings", and get oauth_token and oauth_token_secret.
@nowlinuxing
nowlinuxing / gist:7116228
Created October 23, 2013 10:30
Work with github issue and pull request
@nowlinuxing
nowlinuxing / gist:6547747
Last active December 22, 2015 23:38
AR condition using arel table

Arel Table

OR condition query

admins = User.where(:kind => :admin).where_values.reduce(:and)
authors = User.where(:kind => :author).where_values.reduce(:and)
@nowlinuxing
nowlinuxing / gist:6435240
Created September 4, 2013 10:23
execute Controller#action via rails runner with user authentication (devise)
rails runner "ApplicationController.allow_forgery_protection = false; s = ActionDispatch::Integration::Session.new(Rails.application); s.post('/login', user: {login: 'admin', password: 'password'}); s.get('/my'); puts s.response.body"
@nowlinuxing
nowlinuxing / gist:6362609
Created August 28, 2013 06:09
slow response ranking of production log of Rails
awk '/^Started /{t=$8} /^Completed /{print t,$5,$7,$10}' log/production.log | sort -k 2,2nr | head -20
@nowlinuxing
nowlinuxing / gist:6171837
Created August 7, 2013 07:05
get/post to controller#action on rails c
ApplicationController.allow_forgery_protection = false
app.instance_eval do
post('/login', user: {login: 'bob', password: 'pass'})
get("/my")
puts response.body
end
@nowlinuxing
nowlinuxing / trans_railslog.rb
Created July 24, 2013 08:21
A skelton script to transform Rails log
#!/usr/bin/env ruby
buf = {}
ARGF.readlines.each do |l|
case l.chomp
when /^Started ([^\s]+) "([^\s]+)" .* at ([-0-9]+) ([:0-9]+).*/
_, method, path, date, time = Regexp.last_match.to_a
buf.merge!(:method => method, :path => path, :date => date, :time => time)
when /^Completed/
puts "%s %s %s" % [buf[:time], buf[:method], buf[:path]]
class FoosController < ApplicationController
skip_before_filter :verify_authenticity_token
end
$ curl -i -X PUT -H "Content-Type: application/json; charset=utf-8" -d '{"title": "hoge"}' http://localhost:3000/foos/123.json