Skip to content

Instantly share code, notes, and snippets.

View ksss's full-sized avatar
🏠
Working from home

Yuki Kurihara ksss

🏠
Working from home
View GitHub Profile
#! /usr/bin/env ruby
module Hello
class World
def hi
"wow"
end
end
class Foo
@ksss
ksss / kstruct.rb
Created August 17, 2015 02:11
Keyword argument struct
#! /usr/bin/env ruby
class KStruct
class NoMemberError < StandardError
end
def self.new(*args)
Class.new do
attr_accessor *args
const_set :MEMBERS, args
@ksss
ksss / lib.rb
Created August 12, 2015 22:06
File scope method
class OpenClass
module InternalMethods
refine OpenClass do
def foo
:foo
end
end
end
using InternalMethods
def bar
#! /usr/bin/env ruby
class S3
def buckets
BucketCollection.new
end
class BucketCollection
def [](name)
Bucket.new(name)
#! /usr/bin/env ruby
#$ ruby better_select.rb
#=> read2
#=> end
require 'thread'
def better_select(reads, writes={}, excepts={}, timeout=nil)
rs, ws, es = IO.select(reads.keys, writes.keys, excepts.keys, timeout)
@ksss
ksss / ec2.go
Last active September 30, 2015 11:19
package main
import (
"flag"
"fmt"
"log"
"net/url"
"strings"
"github.com/aws/aws-sdk-go/aws"
module Base58
class InvalidCharError < StandardError; end
WORDS = %w(
1 2 3 4 5 6 7 8 9
a b c d e f g h i j k m n o p q r s t u v w x y z
A B C D E F G H J K L M N P Q R S T U V W X Y Z
).freeze
WORD_MAP = WORDS.each_with_index.to_h
#! /usr/bin/env ruby
require 'socket'
case ARGV[0]
when 'server'
sockfile = "/tmp/test.sock"
File.unlink(sockfile) if File.exists?(sockfile)
UNIXServer.open(sockfile) do |serv|
File.chmod(0777, sockfile)
// imagemagick_server
// $ go run imagemagick_server.go -host 127.0.0.1:8088
// GET http://127.0.0.1:8088/fill/300/300/example.com/path/to/name
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
@ksss
ksss / imagemagick.rb
Last active August 29, 2015 14:14
e.g) GET /{filename}/fit/300/300
module MrubyMiniMagick
class Convert
attr_accessor :opts
def initialize(src, dst)
@opts = []
@src = src
@dst = dst
end
%i(resize define gravity background extent thumbnail).each do |name|
define_method(name) do |value|