Skip to content

Instantly share code, notes, and snippets.

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

Yuichi Tateno (secon) hotchpotch

🏠
Working from home
View GitHub Profile
BoldAsFont=no
CursorType=block
Font=Ricty Diminished
FontHeight=14
WindowShortcuts=no
Transparency=off
FontSmoothing=full
Term=xterm-256color
Locale=ja_JP
Charset=UTF-8
@hotchpotch
hotchpotch / file0.txt
Last active August 29, 2015 14:27
A/D コンバータの MCP3002, MCP3208 を raspberry pi 上の Ruby から扱う ref: http://qiita.com/hotchpotch/items/5c47ae210a7a8e9fd6d1
require 'spi_mcp'
mcp = MCP3208.new
val = mcp.channel(0)
puts val # 0 ~ 4095
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
#!/usr/bin/ruby
# encoding: UTF-8
if `pbpaste`.match(/“(.*?)”/m)
target = $1.chomp
require 'open3'
puts target
Open3.popen3( 'pbcopy' ) {|input, _, _| input << target }
end
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 December 12, 2013 11:11
glitch in RubyMotion (memo)
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 December 14, 2015 18:59
elasticsearch homebrew formula 0.90.0.Beta1
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?
#!/usr/bin/env ruby
require 'msgpack'
require 'pp'
while gets
line = $_.strip
begin
pp MessagePack.unpack(line)
rescue EOFError => e
#!/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 }
def destroy_all(conditions = nil)
if conditions
where(conditions).destroy_all
else
to_a.each {|object| object.destroy }.tap { reset }
end
end