Skip to content

Instantly share code, notes, and snippets.

queue = Queue.new
rest = ***
stream = ***
Thread.new do
loop do
delete_time, tweet = queue.pop
wait_time = delete_time - Time.now
sleep wait_time if wait_time > 0
rest.destroy_status tweet
@tompng
tompng / hanabi_web.html
Created February 13, 2014 07:38
Hanabiのweb版 動いてるのを見たい人は→ http://dl.dropboxusercontent.com/u/102060740/hanabi/pusherapp.html サーバサイドは https://github.com/tompng/tompng-pusher 使ってます
<meta charset='utf-8'>
<script>var PUSHER_ENDPOINT='tompng-pusher.herokuapp.com:80'</script>
<script src='http://tompng-pusher.herokuapp.com:80/socket.io/socket.io.js'></script>
<script src='http://tompng-pusher.herokuapp.com:80/jspusher.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>
<script>
var server=new Server();
function gameStart(room){
Pusher.init(room);
Pusher.ondata=function(data){
require './hoge'
Printer3D.generate 'out.stl' do
x------------------------------x
x-!--------------------------!-x
x--!!!--------------------!!!--x
x---!!!------------------!!!---x
x---!!!------------------!!!---x
x----!!!----------------!!!----x
x----!!!----------------!!!----x
<script>
var allPoints=[];
var lines=[];
function dist(p1,p2){
return (p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y);
}
function check(points, d){
var out=[];
<meta charset=utf-8>
<script>
function SVG(width, height){
this.width=width;
this.height=height;
this.content='';
this.lineWidth=1;
this.trans={x:0,y:0,w:1,h:1};
}
SVG.prototype={
@tompng
tompng / each.c
Last active August 29, 2015 14:00
eachマクロいろいろ試してる
#include <stdio.h>
#define each_old(type, arr, code) {int _i;for(_i=0;_i<sizeof(arr)/sizeof(arr[0]);_i++){type=arr[_i];code}}
#define each(arr, type) {int _i;for(_i=0;_i<sizeof(arr)/sizeof(arr[0]);_i++){type=arr[_i];
#define end }}
int main(){
int array[]={1,2,5,4,3,2,1};
char* sarr[]={"hello", "world", "foo"};
@tompng
tompng / vhash.rb
Last active August 29, 2015 14:00
GCされるまでキャッシュするハッシュ object_idが使い回されるからhash値も比較した。segfaultでよく落ちる...
class VolatileHash
def initialize
@keys = []
@hash = {}
end
def []= key, value
clean
if @hash.key? key
@hash[key][:id] = value.object_id
require 'net/http'
require 'json'
module Minecraft
class Client
def initialize host
@host = host
end
def get path
Net::HTTP.get URI.parse("http://#{@host}#{path}")
end
def get patterns
loop do
s = gets
p = patterns.find{|p|p=~s}
return [p, s] if p
end
end
number = /\d+/
word = /[a-z]+/
@tompng
tompng / shiritori_telnet.rb
Last active August 29, 2015 14:01
telnetでみんなでshiritori $ telnet localhost 1234
require 'socket'
require 'shiritori'
queue = Queue.new
shiritori = Shiritori::Main.new
sockets = []
shiritori.define_singleton_method :get_command do
queue.deq
end