Skip to content

Instantly share code, notes, and snippets.

takeshy takeshy

Block or report user

Report or block takeshy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@takeshy
takeshy / app.js
Last active Aug 29, 2015
socket.ioでiPhone,Androidでローディングが続く問題
View app.js
var static = require('node-static');
var file = new static.Server('.');
server = require('http').createServer(function (request, response) {
request.addListener('end', function () {
file.serve(request, response);
}).resume();
})
server.listen(60000);
var io = require('socket.io').listen(60001);
io.sockets.on('connection', function(socket){
View calc_month.rb
def calc_month(t,n)
y = t.year
m = t.month + n
if m < 1
y += ((m-1)/12).floor
m = 12 + (m % -12)
elsif m > 12
y += (m/12).floor
m = ((m-1) % 12) + 1
end
@takeshy
takeshy / index.html
Created Dec 18, 2013
socket.io-reqev用demo index.html
View index.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/underscore.js"></script>
<script type="text/javascript" src="js/backbone.js"></script>
<script type="text/javascript" src="js/socket.io.min.js"></script>
<script type="text/javascript" src="js/io-reqev-client.js"></script>
<title>sample</title>
</head>
@takeshy
takeshy / timer.js
Last active Dec 31, 2015
socket.io-reqev用demo timer.js
View timer.js
var events = require('events');
var Timer = function(){
this.events = ["five","ten","thirty"];
var that = this;
setInterval(function (){
var now = new Date();
if(now.getSeconds() % 5 == 0){
that.emit("five", {time: now.toString()});
}
if(now.getSeconds() % 10 == 0){
@takeshy
takeshy / app.js
Created Dec 18, 2013
socket.io-reqev デモアプリ サーバー側 app.js
View app.js
var IOReqEv = require('socket.io-reqev');
var ioReqEv = new IOReqEv(require('socket.io').listen(50000));
var Timer = require('./timer');
ioReqEv.register("/timer",new Timer());
//temporary web server
var static = require('node-static');
var file = new static.Server('.');
require('http').createServer(function (request, response) {
request.addListener('end', function () {
file.serve(request, response);
@takeshy
takeshy / database.rb
Last active Dec 26, 2015
database wrapper for mysql2 and sqlite3 and postgresql
View database.rb
require 'yaml'
require 'logger'
RAILS_ENV = ENV["RAILS_ENV"] || "development"
ROOT = File.dirname(File.expand_path("../",__FILE__))
DB_SETTING = YAML.load_file(ROOT + "/config/database.yml")[RAILS_ENV]
class DataBaseWrapper
attr_reader :client
def initialize(log = Logger.new(STDOUT))
@log = log
case DB_SETTING["adapter"]
@takeshy
takeshy / battle.coffee
Created Sep 28, 2013
第14回 オフラインリアルタイムどう書く http://nabetani.sakura.ne.jp/hena/ord14linedung/
View battle.coffee
Weapons = ['a','c', 'e', 'g', 'i', 'k']
class Monster
@Weak =
'B': 'a'
'D': 'c'
'F': 'e'
'H': 'g'
'J': 'i'
'L': 'k'
@takeshy
takeshy / summer_time.js
Last active Dec 22, 2015
check if Daylight Saving Time using JavaScript. 夏時間判定
View summer_time.js
//3月の第2日曜日
function summerTimeStart(y){
var first = new Date(y,2,8);
var i = 9;
while(first.getDay() != 0){
first = new Date(first.setDate(i++));
}
return first;
}
//11月の第1日曜日
@takeshy
takeshy / app.js
Last active Dec 17, 2015
asset pipline & minify & gzip and s3 upload for node.js
View app.js
require('./lib/compiled');
app.configure('development', function(){
var Mincer = require('mincer');
var environment = new Mincer.Environment();
environment.appendPath(__dirname + '/app/assets/javascripts');
app.use('/assets', Mincer.createServer(environment));
ASSET_JS_PATH = null
});
app.get('/', index);
@takeshy
takeshy / search_no_use_port.js
Created Mar 21, 2013
node.jsで使っていないポートを取得する
View search_no_use_port.js
function getPort(host,port,maxPort,callback) {
var net = require('net');
var socket = new net.Socket();
socket.on('error', function(e) {
if(e.code == 'ECONNREFUSED'){
callback(null, port);
return;
}
loop(++port);
});
You can’t perform that action at this time.