Skip to content

Instantly share code, notes, and snippets.

View geetfun's full-sized avatar

Simon Chiu geetfun

View GitHub Profile
@geetfun
geetfun / Orderize
Created October 23, 2009 02:35
To sort order
orderize: function(options) {
var sortOrder = [];
if (!options) {
var options = $.shopscaler.productOptions.container.find("li");
options.each(function(i) {
sortOrder.push($(this).attr("id").split("-")[2]);
});
} else {
$.each(options, function() {
alert(this.split("-")[2]);
@geetfun
geetfun / Another sort
Created October 23, 2009 04:10
orderize again
orderize: function() {
var options = $.shopscaler.productOptions.container.find("li");
options.each(function(count) {
var $this = $(this);
var previousOrder = $this.attr("id").split("-")[1];
if (previousOrder != count) {
var hiddenTag = $("#product_options_attributes_"+previousOrder+"_id");
if (hiddenTag.size() == 1) {
Attribute.replace_id(hiddenTag, "id", "_"+previousOrder+"_", "_"+count+"_");
var Attribute = {
replace_id: function(selector, attribute, oldVal, newVal) {
var oldValue = selector.attr(attribute);
var newValue = oldValue.replace(oldVal, newVal);
selector.attr(attribute, newValue)
return selector;
}
};
require 'nokogiri'
require 'pstore'
#
# Rack::DomainSprinkler
#
# Modifies outgoing HTML markup so that common static assets like script source
# files, images, and stylesheets will be served from one of a number of domains
# rather than just a single one in order to improve parallelization of resource
[color]
diff = auto
status = auto
branch = auto
# Put this file eg. xml_parser.rb into your config/initializers directory, reboot your application
ActiveSupport::XmlMini.backend = "Nokogiri"
module ActiveSupport
module XmlMini_Nokogiri
def parse(data)
if !data.respond_to?(:read)
data = StringIO.new(data || '')
@geetfun
geetfun / threaded_terminal.rb
Created March 7, 2011 03:28
Simple Ruby program that uses serialport gem to connect with a serial-attached device
require 'serialport'
require 'highline/import'
class HighLine
public :get_character
end
class ThreadedTerminal
class << self
MODEM = '/dev/tty.usbmodem0000001'
@geetfun
geetfun / grape_api_sample.rb
Created June 4, 2011 02:53 — forked from yorzi/grape_api_sample.rb
a well documented ruby api based on GrapeAPI.
require 'grape'
module My
class API < Grape::API
prefix 'api'
## params key list
#################################################################################################################
# 1. login
# 2. sign
@geetfun
geetfun / i18n.coffee
Created November 14, 2011 16:04 — forked from madrobby/i18n.coffee
Backbone i18n with CoffeeScript
window.t = (id, vars = {}) ->
template = i18n[__locale][id] or i18n['en'][id] or "(?) #{id}"
_.template(template, vars)
# yes, that's it
@geetfun
geetfun / chef_solo_bootstrap.sh
Created June 21, 2012 00:18 — forked from ryanb/chef_solo_bootstrap.sh
Bootstrap Chef Solo
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar -xvzf ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194/
./configure --prefix=/usr/local
make
make install