Skip to content

Instantly share code, notes, and snippets.

@Martin91
Martin91 / track_original_repo.sh
Created July 2, 2013 12:37
Make Your Fork Track the Original Upstream Repo
git remote add --track master upstream git://github.com/upstreamname/projectname.git
git fetch upstream
git merge upstream/master
@Martin91
Martin91 / bubble_sort.cpp
Last active December 26, 2015 21:38
A bubble sort example based on C++ source code
#include <iostream>
using namespace std;
void bubbleSort(int array[], int length)
{
for(int i = 0; i < length - 1; i ++)
{
for(int j = length - 1; j > i; j--)
{
@Martin91
Martin91 / joseph.rb
Created October 29, 2013 16:28
A ruby implementation for Josephus problem
Array.class_eval do
def joseph(k, m)
people = ((k - 1) + (m - 1)) % length
puts delete(self[people])
while(length > 1) do
people = (people + (m - 1)) % length
puts delete(self[people])
end
@Martin91
Martin91 / admin_resource_name.rb
Created November 18, 2013 05:34
active admin add custom plain text in a form
f.form_buffers.last << javascript_include_tag("http://api.map.baidu.com/api?v=1.5&ak=shf992u0sf90sf907adjsfsisha7")
@Martin91
Martin91 / git_prune.sh
Last active December 28, 2015 15:39
[Git] Remove stale remote track branches
# Deletes all stale remote-tracking branches under <name>.
# These stale branches have already been removed from the remote
# repository referenced by <name>, but are still locally available
# in "remotes/<name>".
git remote prune origin
# Or, which fetches and prunes all origins.
git fetch -p
@Martin91
Martin91 / run test.sh
Last active January 1, 2016 00:09
Run single test example or test case with Rake task or ruby command line
# In Rails 3.2.x
# You can run a single test based on a file like:
rake test TEST=test/functionals/xxx_controller_test.rb
# Or even a single test example like:
ruby -I 'lib:test' test/functionals/xxx_controller_test.rb -n test_edit_profile_without_login
# In Rails 4.x.x
# You can run a single test based on a file like:
rake test /test/functionals/xxx_controller_test.rb # Notice: We don't need TEST system variable any more!
@Martin91
Martin91 / start shoes.md
Created January 3, 2014 16:08
alias for running shoes app

Under Mac OS, the Shoes' bin command line located at /Applications/Shoes.app/Contents/MacOS/shoes, you can write a alias to conveniently start the shoes app in your terminal like:

# ~/.bashrc
alias shoes='/Applications/Shoes.app/Contents/MacOS/shoes'

Even more you can specify a file to start any shoes app:

$ shoes path/to/shoes/app/file
@Martin91
Martin91 / mysql examples.md
Last active January 2, 2016 06:48
Mysql sql statements

If not any statement, all the following commands running in the mysql console or a query string.

# Alter table syntax: http://dev.mysql.com/doc/refman/5.6/en/alter-table.html
#   ALTER [IGNORE] TABLE tbl_name
#     [alter_specification [, alter_specification] ...]
#     [partition_options]
ALTER TABLE users ADD username CHAR(30), ADD email CHAR(30);

# Even more, if the name of your column includes a blank space, you should use a pair of ` symbol:
@Martin91
Martin91 / add tracking ids.rb
Created January 23, 2014 07:19
Use selenium web driver to add new tracking IDs for amazon's affiliate
require 'selenium-webdriver'
ASSOCIATE_ACCOUNT = { email: 'test@test.com', password: 'password' }
TRACKING_IDS_SUFFIX = 1..100 # By default, only 100 trackings IDs is supported
TRACKING_IDS_PREFIX = 'tracking_id' # Whatever unique characters you like
driver = Selenium::WebDriver.for :firefox
driver.navigate.to 'https://affiliate-program.amazon.com/'
# Fill in the account's email
@Martin91
Martin91 / retrieve tracking ids.rb
Last active January 4, 2016 05:49
Retrieve tracking ids for Amazon associates through selenium web driver
require 'selenium-webdriver'
require 'csv'
# require 'pry'
ASSOCIATE_ACCOUNT = { email: 'demo@demo.com', password: 'password' }
driver = Selenium::WebDriver.for :firefox
driver.navigate.to 'https://affiliate-program.amazon.com/'
# Fill in the account's email