Skip to content

Instantly share code, notes, and snippets.

View xiaods's full-sized avatar
🌏
Coding for Fun

Deshi Xiao xiaods

🌏
Coding for Fun
View GitHub Profile

Given an integer, and a range of integers (both positive and negative) as input.

We need to calculate the possible combinations of the integers from the range that add up to the given integer.

For example:

Integer: 5

Range: -1, 0, 1, 2, 3, 4

@sputnikus
sputnikus / gist:1014627
Created June 8, 2011 15:20
Deployment process on OpenShift
# generic install and usage of rhc
# install rhc gem
export RB_USER_INSTALL=true
export PATH=$PATH:/home/holly/.gem/ruby/1.8/bin
gem install --user-install --source http://gems.rubyforge.org --source https://openshift.redhat.com/app/repo/ rhc
# json-1.5.1
# parseconfig-0.5.2
# rhc-0.69.3
@wesen
wesen / backbone-mixin.js
Created August 21, 2011 10:38
Merge backbone views (mixin pattern)
/**
* ## Merging mixin views in backbone.js ##
*
* really just more a test for tumblr gistr
*/
/**
* Merge the mixin (a Backbone.View) into another Backbone.View. Automatically merge events, defaults, and call the parent initializer.
**/
function mergeMixin(view, mixin) {
@havenwood
havenwood / palindrome.rb
Created September 13, 2011 15:54
Find Palindromes
#!/usr/bin/env ruby
require "rubygems"
gem "minitest"
require "minitest/autorun"
require "minitest/pride"
class Palindrome
def search string
@array = string.gsub(/[^0-9a-z ]/i, '').gsub(' ', '').downcase.split ''
@palindromes = []
@thermistor
thermistor / assets.rake
Created October 20, 2011 13:55 — forked from shedd/assets.rake
Check asset encoding for valid UTF-8
namespace :assets do
desc "Check that all assets have valid encoding"
task :check => :environment do
paths = ["app/assets", "lib/assets", "vendor/assets"]
extensions = ["js", "coffee", "css", "scss"]
paths.each do |path|
dir_path = Rails.root + path
@sgonyea
sgonyea / nginx_log_regex.rb
Created November 30, 2011 19:07
A documented regex, Ruby. You can do this. It's great.
def log_regex
@log_regex ||= begin
ip_regex = '(?:\d+\.){3}\d+'
log_regex = /^
(#{ip_regex})\s-\s-\s # IP
\[(.*?)\]\s # Date
"(.*?)"\s # Request
(\d+)\s # Response Code
(\d+)\s # Bytes Sent by Server
([\d\.]+)\s # Request Time
@ryandotsmith
ryandotsmith / instruments.rb
Created April 6, 2012 07:09
Sequel & Sinatra Instrumentation
module Instruments
def self.set_logger(l, m)
@logger = l
@method = m
end
def self.logger
@logger
end
@thorn
thorn / get_url_params.js.coffee
Created May 23, 2012 13:14
getting url params with coffeescript and jquery
# Returns get parameters.
#
# If the desired param does not exist, null will be returned
#
# To get the document params:
# @example value = $(document).getUrlParam("paramName");
#
# To get the params of a html-attribut (uses src attribute)
# @example value = $('#imgLink').getUrlParam("paramName");
jQuery.fn.extend
@quark-zju
quark-zju / spec_fetcher.rb
Created October 22, 2012 13:51
Patched ruby-1.9.3-p{194,286}/lib/ruby/1.9.1/rubygems/spec_fetcher.rb to prefer local cached version even it's a little out-dated. This makes gem / bundle command a lot faster under slow Internet connection.
require 'rubygems/remote_fetcher'
require 'rubygems/user_interaction'
require 'rubygems/errors'
require 'rubygems/text'
##
# SpecFetcher handles metadata updates from remote gem repositories.
class Gem::SpecFetcher
@doitian
doitian / edit.html.erb
Created December 16, 2012 13:11 — forked from masqita/type_caster.rb
Add a active model wrapper to edit settings in form. `type_caster.rb` can be put in lib directory, which convert the field to specific type. The wrapper idea also can be used to wrap any other object, such as [Railscasts #396](https://github.com/railscasts/396-importing-csv-and-excel/blob/master/store-with-validations/app/models/product_import.rb)
<h1>Settings</h1>
<%= simple_form_for @settings, :as => 'settings', :url => admin_settings_path, :html => { :class => 'form form-horizontal' } do |f| %>
<fieldset>
<legend>Points Earning</legend>
<%= f.input :site_name %>
<%= f.input :per_page %>
</fieldset>
<div class="control-group">