Skip to content

Instantly share code, notes, and snippets.

@u1tnk
u1tnk / gist:1941518
Created February 29, 2012 15:21
grep and replace by ruby oneliner
find . -name "*.xml" -print0 | xargs -0 ruby -i -p -e '$_.gsub! %r{hoge}, "fuga"'
Parent = {
hoge = 1
}
function Parent:new (o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
We couldn’t find that file to show.
it "normal" do
a = [{id: 1, weight:1}, {id:2, weight: 3}, {id:3, weight:nil}]
check_count = 10
check_count.times do
sample_count = 1000
counts = {1 => 0, 2 => 0}
sample_count.times do
counts[a.sample_with_weight[:id]] += 1
end
(counts[1] < counts[2]).should be_true
@u1tnk
u1tnk / main.lua
Created February 19, 2013 14:19
CoronaSDKのgroupへのマスクサンプル
local group = display.newGroup()
local rect1 = display.newRect(0, 0, 50, 1000)
rect1:setFillColor(255, 0, 0)
local rect2 = display.newRect(0, 0, 1000, 50)
rect2:setFillColor(0, 255, 0)
group:insert(rect1)
group:insert(rect2)

Ending

Unixのプロセスの動作はabstractionとcommunicationの二つについてだ

Abstraction

kernelはプロセスの抽象的(シンプル)なビューを持つ 私達のようなプログラマは二つの言語の違いをソースコードから見つけるのに慣れている

私達は色んな用途に使うたくさんのプログラムを習得している。 GCを持つようなプログラムでメモリ効率的なプログラムを書く事は不可能だ、Cを使わなければならない、けど、オブジェクトが必要だ。じゃあC++を使おう…

@u1tnk
u1tnk / bc.rb
Last active December 14, 2015 13:59
画像ファイルのサイズ一覧からでかいの検出した
#!/usr/bin/env ruby
File.open('ids.txt') do |file|
while line = file.gets do
words = line.split(' ')
size = eval(words[1].gsub('x', '*'))
if size >= 640 * 960
p(words)
end
@u1tnk
u1tnk / retire_hosts.rb
Last active August 29, 2015 14:03
working以外のサーバを一括retire
# -*- coding: utf-8 -*-
# mackrel-client-ruby 0.0.2 使用
require 'mackerel'
client = Mackerel::Client.new(:mackerel_api_key => ENV['MACKEREL_APIKEY'])
client.get_hosts(service: 'service_name').each do |host|
# working以外で初期登録から一週間以上経過している
if host.status != "working" && host.createdAt < Time.now.to_i - (60 * 60 * 24 * 7)
p "retire host id:#{host.id}"
p client.retire_host(host.id)
[global]
ioengine=libaio
iodepth=1
size=1g
direct=1
runtime=60
directory=${TARGET}
stonewall
[Seq-Read]
let locale = "jp"
let blacklists = ["*://mail.google.com/*","*://mail.google.com/*","*://mail.google.com/mail/*","*://www.inoreader.com/*","docs.google.com"]
let mapleader = ","
map ; :
map : ;
" macでSKKの変換と同時に動く為無視する
imap <C-j> <Nop>