Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
jhjguxin / rails_time_zone_and_db_time.markdown
Last active August 29, 2015 13:56
rails time zone outside of Rails eg db time
View rails_time_zone_and_db_time.markdown
View caller.ru
# 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 caller.ru"
puts `python #{path_to_script}/processing.py UserName 37`
View maze.rb
#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
require 'gosu'
include Gosu
DIMENSION, SPLITS, COLOR = 200, 50, Color::GREEN
# credits to: http://en.wikipedia.org/wiki/Maze_generation_algorithm
class GameWindow < Window
def initialize
super DIMENSION, DIMENSION, false, 1000
self.caption = "Maze"
View mobile-uploader.rb
#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
require 'sinatra'
set :port, 3000
set :environment, :production
get '/' do
<<-EOT
<html><head>
View coderwall.rb
#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
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
driver.navigate.to "https://coderwall.com/auth/github"
@jhjguxin
jhjguxin / rails_ar_join_sort_demo.rb
Created April 1, 2014 11:58
how rails organization join query and sort them
View rails_ar_join_sort_demo.rb
class WxUser < ActiveRecord::Base
has_many :orders, -> { order('id DESC') }
acts_as_follower
has_many :shop_wx_user_maps
belongs_to :shop
def orders_in_shop(shop_id)
orders.where(shop_id: shop_id)
end
@jhjguxin
jhjguxin / bootstrap-wysihtml5.js
Last active August 29, 2015 13:58
integrate wysihtml5 with qiniu cloud and jquery file upload
View bootstrap-wysihtml5.js
!function($, wysi) {
"use strict";
var tpl = {
"font-styles": function(locale, options) {
var size = (options && options.size) ? ' btn-'+options.size : '';
return "<li class='dropdown'>" +
"<a class='btn dropdown-toggle" + size + "' data-toggle='dropdown' href='#'>" +
"<i class='icon-font'></i>&nbsp;<span class='current-font'>" + locale.font_styles.normal + "</span>&nbsp;<b class='caret'></b>" +
"</a>" +
View node-and-npm-in-30-seconds.sh
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
View angular_tour.md

PhoneCat Tutorial App

A great way to get introduced to AngularJS is to work through this tutorial, which walks you through the construction of an AngularJS web app. The app you will build is a catalog that displays a list of Android devices, lets you filter the list to see only devices that interest you, and then view details for any device.

Follow the tutorial to see how Angular makes browsers smarter — without the use of native extensions or plug-ins:

@jhjguxin
jhjguxin / wshop_api.markdown
Created April 9, 2014 05:50
vcooline wshop api
View wshop_api.markdown
# app/grape/api.rb
###
# http://intridea.github.io/grape/docs/index.html
# http://blog.brunoscopelliti.com/authentication-to-a-restful-web-service-in-an-angularjs-web-app
# http://stackoverflow.com/questions/21255203/angularjs-clientside-routing-and-token-authentication-with-webapi
###
class API < Grape::API
  # prefix "api"
 # version 'v1'