Skip to content

Instantly share code, notes, and snippets.

Avatar
🌴
On vacation

Yuichi Tateno (secon) hotchpotch

🌴
On vacation
View GitHub Profile
View reinstall_ruby_ext.sh
TARGET_EXT=readline; cd ~/.rbenv/sources; for x in *; do cd ~/.rbenv/sources/${x}/ruby-${x}; pwd; rm -vf .ext/*/$TARGET_EXT.bundle ext/$TARGET_EXT/Makefile ext/$TARGET_EXT/*.o; make install-ext; done
View ibook_copy_clean.rb
#!/usr/bin/ruby
# encoding: UTF-8
if `pbpaste`.match(/“(.*?)”/m)
target = $1.chomp
require 'open3'
puts target
Open3.popen3( 'pbcopy' ) {|input, _, _| input << target }
end
View fizzbuzz.swift
extension Int {
func fizzbuzz() -> String {
switch (self % 3 == 0, self % 5 == 0) {
case (true, false):
return "Fizz"
case (false, true):
return "Buzz"
case (true, true):
return "FizzBuzz"
default:
@hotchpotch
hotchpotch / glitch_motion.rb
Created Dec 12, 2013
glitch in RubyMotion (memo)
View glitch_motion.rb
def glitchnize(image_data)
bytes = image_data.bytes
length = image_data.length
d = Pointer.new(:uchar, length)
length.times do |i|
c = bytes[i]
if c == 42 && rand > 0.8
d[i] = rand(255)
else
d[i] = c
@hotchpotch
hotchpotch / elasticsearch.rb
Last active Dec 14, 2015
elasticsearch homebrew formula 0.90.0.Beta1
View elasticsearch.rb
require 'formula'
class Elasticsearch < Formula
homepage 'http://www.elasticsearch.org'
url 'https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.0.Beta1.tar.gz'
sha1 'b2c7381368f8df57d10ce5fa18f55876d5d8969d'
head 'https://github.com/elasticsearch/elasticsearch.git'
depends_on 'maven' if build.head?
View msgpack-unpack
#!/usr/bin/env ruby
require 'msgpack'
require 'pp'
while gets
line = $_.strip
begin
pp MessagePack.unpack(line)
rescue EOFError => e
View web_capture.rb
#!/usr/bin/env ruby
require 'capybara-webkit' # '~> 0.14.0'
require 'optparse'
require 'cgi'
options = {}
OptionParser.new do |opt_parser|
opt_parser.on('-O filename') {|value| options[:filename] = value }
View gist:3410567
def destroy_all(conditions = nil)
if conditions
where(conditions).destroy_all
else
to_a.each {|object| object.destroy }.tap { reset }
end
end
View fluentd.conf.rb
source :forward
source(:http) {
port '8889'
}
foo_path = '/tmp/foo.log'
match(:file, 'heartbeat.**') {
path foo_path
View gist:3057860
require 'timecop'
module ActiveRecordDetectTimeInScopes
extend ActiveSupport::Concern
module ClassMethods
def scope(*args)
scope_caller = caller
Timecop.travel(Time.now) do
Timecop.top_stack_item.define_singleton_method :time do