Skip to content

Instantly share code, notes, and snippets.

View chsh's full-sized avatar
👍
Love your code.

CHIKURA Shinsaku chsh

👍
Love your code.
View GitHub Profile
@chsh
chsh / stone.patch
Created April 18, 2013 04:08
Patch to compile stone (simple repeater http://www.gcd.org/sengoku/stone/ ) on linux. Only add -D_GNU_SOURCE to linux build parameter.
*** stone-2.3d-2.3.2.7.org/Makefile 2008-02-05 08:00:00.000000000 +0900
--- stone-2.3d-2.3.2.7/Makefile 2013-04-18 13:01:12.253674581 +0900
***************
*** 97,103 ****
$(MAKE) FLAGS="-DNT_SERVICE $(FLAGS)" LIBS="$(LIBS) $(SVC_LIBS) -ladvapi32 -luser32 -lshell32 -lkernel32" $(TARGET)
linux:
! $(MAKE) FLAGS="-O -Wall -DCPP='\"/usr/bin/cpp -traditional\"' -DPTHREAD -DUNIX_DAEMON -DPRCTL -DSO_ORIGINAL_DST=80 -DUSE_EPOLL $(FLAGS)" LIBS="-lpthread $(LIBS)" stone
linux-pop:
@chsh
chsh / ejector.rb
Created April 26, 2013 07:21
Volume unmount utility for Mac OS X.
#!/usr/bin/env ruby
class Runner
attr_reader :args
def initialize(args)
@args = args
end
def run
targets = targets_by_args %w(/Volumes/Name1 /Volumes/Name2 /Volumes/Name3)
@chsh
chsh / orders_controller_spec.rb
Created April 30, 2013 13:35
RSpec controller example
require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
@chsh
chsh / orders_spec.rb
Created April 30, 2013 13:38
RSpec requests example
require 'spec_helper'
describe "Orders" do
describe "GET /orders" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get orders_path
response.status.should be(200)
end
end
@chsh
chsh / link.rb
Last active December 16, 2015 23:59 — forked from rmoriz/Gemfile
1. Use SecureRandom.uuid instead of UUIDTools. 2. Belonging models should specify string type refering Site. 3. Apply Ruby 1.9 or higher syntax. ;-)
@chsh
chsh / suppress_deprecation_errors.js
Created May 12, 2013 08:03
Suppress browser error in jQuery 1.9.
(function(jQuery) {
var matched, browser;
// Use of jQuery.browser is frowned upon.
// More details: http://api.jquery.com/jQuery.browser
// jQuery.uaMatch maintained for back-compat
var uaMatch = function( ua ) {
ua = ua.toLowerCase();
@chsh
chsh / extend_object.rb
Created July 17, 2013 01:07
Almost like A || B, but if A is blank, pickup B. ex.) '' || 'A' returns '' ''.present_or 'A' returns 'A'.
class Object
def present_or(value)
return self if self.present?
value
end
end
@chsh
chsh / facebook_ip_range.rb
Created August 26, 2013 06:55
Verify facebook crawler ip range.
require 'ipaddr'
class FacebookIPRange
def self.zones
@@zones ||= build_zones
end
def self.match(ipaddr)
zones.each do |zone|
@chsh
chsh / create_bags_migration.rb
Last active December 22, 2015 04:49
Index to references can be specified on definition time.
class CreateBags < ActiveRecord::Migration
def change
create_table :bags do |t|
t.references :user, index: true
t.timestamps
end
end
end
@chsh
chsh / htpasswd_creator.rb
Last active November 23, 2021 15:35
Generate apache compatible htpasswd file using Ruby.
# generate apache compatible htpasswd file using Ruby.
require 'webrick'
if ARGV.size < 3
puts "usage: #{$0} password-file user password"
exit 1
end
# create htpassword instance