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
  • 03:57 (UTC +08:00)
View GitHub Profile
# Hack below line in canvg.js in svg.parseXml function before deal with the XML
xml = xml.replace(/xmlns=\"http:\/\/www\.w3\.org\/2000\/svg\"/, '');
#!/usr/bin/env ruby
#
# Proof-of-Concept exploit for Rails Unsafe Query Generation (CVE-2013-0155)
#
# ## Advisory
#
# https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/t1WFuuQyavI
#
# ## Synopsis
#

POST a json {"author":[null]} to server via AJAX request or some other Http Tool.

@yorzi
yorzi / transfer-pg-heroku.md
Created January 15, 2013 04:27
Taps is no longer the recommended tool to use when migrating data between postgres instances. Please give heroku-pg-transfer (https://github.com/ddollar/heroku-pg-transfer) a try instead.

First, find the URL to your db on Heroku:

$ heroku config:get DATABASE_URL
postgres://yada:[email protected]:5432/123

Then transfer from the heroku db to your local db:

@yorzi
yorzi / dummy_helpers.rb
Created January 17, 2013 02:41
some common used dummy helpers in Rails application.
module ApplicationHelper
def dummy_image wxh
image_tag "http://dummyimage.com/#{wxh}/999/eee.png",size: wxh
end
def dummy_paragraph(count = 3)
Faker::Lorem.paragraph(count)
end
@yorzi
yorzi / git-revert.text
Created April 4, 2013 08:16
revert git changes.
This depends a lot on what you mean by "revert".
If you want to temporarily go back to it, fool around, then come back to where you are, all you have to do is check out the desired commit:
# this will detach your HEAD, i.e. leave you with no branch checked out.
git checkout 0d1d7fc32
or if you want to make commits while you're there, go ahead and make a new branch while you're at it:
git checkout -b old-state 0d1d7fc32
If, on the other hand, you want to really get rid of everything you've done since then, there are two possibilities. One, if you haven't published any of these commits, simply reset:
@yorzi
yorzi / index.html
Created April 22, 2013 07:49 — forked from tmcw/index.html
<!DOCTYPE html>
<html>
<head>
<script src='http://api.tiles.mapbox.com/mapbox.js/v0.6.4/mapbox.js'></script>
<script src='http://d3js.org/d3.v2.min.js?2.9.3'></script>
<link
href='http://api.tiles.mapbox.com/mapbox.js/v0.6.4/mapbox.css'
rel='stylesheet' />
<style>
body { margin:0; padding:0; }
@yorzi
yorzi / random.rb
Created April 25, 2013 11:57
find random (n) records in mongoid
def self.random(n = 1)
indexes = (0..self.count-1).sort_by{rand}.slice(0,n).collect!
if n == 1
return self.skip(indexes.first).first
else
return indexes.map{ |index| self.skip(index).first }
end
end
@yorzi
yorzi / split_csv.sh
Created April 27, 2013 09:19
a script to split a big csv file into several files.
#!/bin/bash
# check if an input filename was passed as a command
# line argument:
if [ ! $# == 1 ]; then
echo "Please specify the name of a file to split!"
exit
fi
# create a directory to store the output:
@yorzi
yorzi / share_to_facebook.erb
Created May 10, 2013 14:02
share to facebook with necessary information attached by default form.
<% content_for :html_head_content do %>
<meta property="og:title" content="<%= @post.title %>"/>
<meta property="og:type" content="website"/>
<meta property="og:site_name" content="sample.com"/>
<% if Rails.env == 'production' %>
<meta property="og:image" content="http://sample.com/assets/logo.png"/>
<% else %>
<meta property="og:image" content="http://sample.com/logo.png"/>
<% end %>
<meta property="og:description" content="<%= strip_tags(@post.excerpt).strip[0, 200] %>"/>