Skip to content

Instantly share code, notes, and snippets.


jhjguxin jhjguxin

View GitHub Profile
# simple ruby code example for running python script
path_to_script = File.dirname(__FILE__)
puts "It's a ruby script"
puts "Run python script with backticks"
puts "Result is available in"
puts `python #{path_to_script}/ UserName 37`
View mobile-uploader.rb
#!/usr/bin/env ruby
# Author : Emad Elsaid (
require 'sinatra'
set :port, 3000
set :environment, :production
get '/' do
View maze.rb
#!/usr/bin/env ruby
# Author : Emad Elsaid (
require 'gosu'
include Gosu
# credits to:
class GameWindow < Window
def initialize
super DIMENSION, DIMENSION, false, 1000
self.caption = "Maze"
View coderwall.rb
#!/usr/bin/env ruby
# Author : Emad Elsaid (
require "selenium-webdriver" # gem install selenium-webdriver
require "highline/import" # gem install highline
def coderwall github_email, github_password, title, content, tags
driver = Selenium::WebDriver.for :firefox ""
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl | sh
jhjguxin / jquery.parseparams.js
Last active Aug 29, 2015 — forked from kares/jquery.parseparams.js
This function is meant to be used with an URL like the window.location
View jquery.parseparams.js
// Add an URL parser to JQuery that returns an object
// This function is meant to be used with an URL like the window.location
// Use: $.parseParams('') or $.parseParams() to parse the window.location
// Simple variable: ?var=abc returns {var: "abc"}
// Simple object: ?var.length=2&var.scope=123 returns {var: {length: "2", scope: "123"}}
// Simple array: ?var[]=0&var[]=9 returns {var: ["0", "9"]}
// Array with index: ?var[0]=0&var[1]=9 returns {var: ["0", "9"]}
// Nested objects: ? returns {my: {var: {is: {here: "5"}}}}
// All together: ?var=a&my.var[]=b&my.cookie=no returns {var: "a", my: {var: ["b"], cookie: "no"}}
// You just cant have an object in an array, ?var[1].test=abc DOES NOT WORK
View each_slice.js
Array.prototype.each_slice = function (size, callback){
for (var i = 0, l = this.length; i < l; i += size){, this.slice(i, i + size));
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].each_slice(3, function (slice){
jhjguxin /
Created May 24, 2012 — forked from dongyi/
# -*- Encoding: utf-8 -*-
import base64
import binascii
import cgi
import hashlib
import hmac
import logging
import time
import urllib
import urlparse
View render_and_redirect.markdown

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.


The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.


jhjguxin / rails_template_for_mongoid.rb
Created Jun 11, 2012 — forked from huacnlee/rails_template_for_mongoid.rb
A custom Rails template for Mongoid.
View rails_template_for_mongoid.rb
# coding: utf-8
# This is a Rails init template with MongoDB projects
# Mongoid, Devise, Bootstrap, jQuery, Redis, Cells, will_paginate, Carrierwave, simple_form, Settingslogic, Thin
# Usage
# $ rails new app_name -m