Skip to content

Instantly share code, notes, and snippets.

View yorzi's full-sized avatar
🏠
Working from home

Andy Wang yorzi

🏠
Working from home
  • Xi'an, China
  • 11:26 (UTC +08:00)
View GitHub Profile
@yorzi
yorzi / auto_capture.rb
Created December 22, 2012 10:02
simple sample script to do auto screenshots when browsing some website pages.
#!/usr/bin/env ruby
country_array = %w(
aruba
afghanistan
andorra
angola
anguilla
albania
united-arab-emirates
@yorzi
yorzi / postgis.md
Created December 20, 2012 12:21
enable postgis in postgresql database, use heroku's Postgres.app for instance.

connect to postgres psql -h localhost

create database CREATE DATABASE mydatabase;

switch to your database \connect mydatabase

add postgis extension

@yorzi
yorzi / dump_restore_postgres.md
Last active December 9, 2015 23:29
dump / restore postgresql database.

To dump:

pg_dump dbname > dbname.sql

To restore:

cat dbname.sql | psql dbname

NOTICE:

@yorzi
yorzi / creating-edgerails-app.sh
Created November 26, 2012 05:48 — forked from peter/creating-edgerails-app.sh
Creating and Deploying an EdgeRails (Rails 4) Application to Heroku
# 0. Make sure you have Ruby 1.9.3 installed, and optionally RVM and PostgreSQL
# 0.2 If you are on the Mac, make sure you have a c compiler by installing XCode Command Line Tools or gcc4.2 with homebrew
# https://github.com/mxcl/homebrew/wiki/Custom-GCC-and-cross-compilers
# 0.5 Make sure you have bundler version ~> 1.2 as Rails depends on it
gem install bundler
# 1. Get edge Rails source (master branch)
git clone https://github.com/rails/rails.git
@yorzi
yorzi / dummy image place holder in rails
Created June 12, 2012 12:56
dummy_image_helper.rb
module DummyImageHelper
def dummy_image wxh
image_tag "http://dummyimage.com/#{wxh}/999/eee.png",size: wxh
end
end
@yorzi
yorzi / Limit chosen select count
Created June 12, 2012 01:19
limit_chosen_count.coffee
$(".chzn").change ->
el = $(@)
if el.val()? == false or el.val().length < 3
exists = 0
exists = el.val().length if el.val()?
$(".metro-stations-counter").html("You can add <strong>#{2 - exists}</strong> more metro station(s) to this organization.</span>")
else
el.val(el.val().slice(0, el.val().length - 1))
el.trigger("liszt:updated")
@yorzi
yorzi / command.sh
Created April 3, 2012 13:26
pull data from heroku to local postgres
# make sure you have latest version of below gems
gem install heroku taps sequel
# run command
# heroku db:pull postgres://db_username:@localhost/db_name
heroku db:pull postgres://andy:@localhost/newsite_development
@yorzi
yorzi / xhtml-validation.md
Created March 15, 2012 03:38
XHTML validation on pew county#show page

Validation Output: 32 Errors

Line 6, Column 13: there is no attribute "class"

✉ You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).

This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chos

@yorzi
yorzi / command_output.rb
Created February 15, 2012 01:45
get command output in ruby code
require 'pty'
cmd = "rake -T"
begin
PTY.spawn( cmd ) do |stdin, stdout, pid|
begin
# Do stuff with the output here. Just printing to show it works
stdin.each { |line| print line }
rescue Errno::EIO
puts "Errno:EIO error, but this probably just means " +
"that the process has finished giving output"
@yorzi
yorzi / 01. Gemfile
Created February 3, 2012 13:30 — forked from schleg/01. Gemfile
Setup for Devise + Omniauth
gem 'pg'
group :development do
gem 'ruby-debug'
end
gem 'rake', '~> 0.8.7'
gem 'devise'
gem 'oa-oauth', :require => 'omniauth/oauth'
gem 'omniauth'
gem 'haml'
gem 'dynamic_form'