Skip to content

Instantly share code, notes, and snippets.

takeshy takeshy

View GitHub Profile
@takeshy
takeshy / read_ts.vim
Last active Jul 11, 2018
typescriptのimport先のファイルの読み込み
View read_ts.vim
function! ReadFile() abort
let s:currentPos = col('.')
let s:colNum = s:currentPos - 1
let s:lastPos = len(getline('.'))
let s:fileName = ''
let s:ext = '.' . expand("%:e")
while s:colNum > -1
if getline('.')[s:colNum] =~ "\['\"\]"
break
end
View confirm_git_branch_D.rb
#!/usr/bin/env ruby
branches = `git branch`
branches.each_line do|line|
branch = line.gsub(/\s/,"")
next if branch[0] == "*"
puts "################"
puts "#{branch}\n"
puts "################"
puts `git branch -d #{branch}`
@takeshy
takeshy / app.js
Last active Dec 26, 2017
Node.js with Backbone.js for CSRF Protection
View app.js
app.use(express.session());
app.use(express.csrf());
app.get('/', index);
index = function(req,res,next){
res.render('index',{token: req.session._csrf});
}
@takeshy
takeshy / readfile.vim
Last active Sep 3, 2016
javascriptでimport先のファイルやejsファイルをsplitで開く
View readfile.vim
function! ReadJSFile() abort
let s:currentPos = col('.')
let s:colNum = s:currentPos - 1
let s:lastPos = len(getline('.'))
let s:fileName = ''
while s:colNum > -1
if getline('.')[s:colNum] =~ "\['\"\]"
break
end
@takeshy
takeshy / .mongorc.js
Last active Mar 19, 2016
現在の時間から指定された秒より前のISODateを作成して、Mongo Shellで検索しやすくする
View .mongorc.js
function zp(num){
return(num < 10 ? "0"+num.toString() : num.toString());
}
function toISODate(d){
return ISODate(d.getUTCFullYear() + "-" + zp(d.getUTCMonth() + 1) + "-" + zp(d.getUTCDate()) + "T"+zp(d.getUTCHours()) + ":" + zp(d.getUTCMinutes()) + ":" + zp(d.getUTCSeconds()));
}
function before(n){
return toISODate(new Date(Date.now() - n * 1000));
}
//accessコレクションのTimeフィールドのDataが600秒(10分)以内のレコードを検索
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"]
You can’t perform that action at this time.