Skip to content

Instantly share code, notes, and snippets.

@kumabook
kumabook / Observable.swift
Last active March 12, 2022 06:47
Observer pattern with swift protocol extension
import Foundation
public protocol Observer: Equatable {
associatedtype EventType
func listen(_ event: EventType)
}
public protocol Observable {
associatedtype ObserverType: Observer
associatedtype EventType
@kumabook
kumabook / gen_post.rb
Created March 8, 2016 12:05
Create jekyll new post
require 'erb'
title = ARGV[0]
categories = ARGV[1]
now = Time.new()
file_name = "#{now.strftime('%Y-%m-%d')}-#{title}.markdown"
puts "title: #{file_name}"
@kumabook
kumabook / file0.txt
Last active January 27, 2016 07:12
xcodeproj gemでxcschemeを弄ってみる ref: http://qiita.com/kumabook/items/cea89fc2ac7c1691b0fe
#!/usr/bin/env ruby
require 'xcodeproj'
lang = ARGV[0]
if lang.nil?
puts "no language is specified"
exit 1
end
@kumabook
kumabook / gist:c84bcbbad1c44675e74a
Created March 1, 2015 12:10
Protocol 'ObserverProtocol' can only be used as a generic constraint because it has Self or associated type requirements
protocol ObserverProtocol: Equatable {
func notified()
}
class Observable: NSObject {
var observers: [ObserverProtocol] = []
override init() {
super.init()
}
func addObserver(observer: ObserverProtocol) {
@kumabook
kumabook / logger_injection.coffee
Created May 29, 2014 13:12
esprima, estraverse, escodegen使ってjavascriptの関数すべてにトレースログを仕込んでみる ref: http://qiita.com/kumabook/items/d84437185ca44f7a96e1
esprima = require 'esprima'
escodegen = require 'escodegen'
estraverse = require 'estraverse'
fs = require 'fs'
_funcID = 0
logger = (funcID, fileName, node, parent, loc) ->
name = 'anonymous'
if node.id?
@kumabook
kumabook / inject-logger.coffee
Last active August 23, 2016 21:19
Inject log code to JavaScript function
esprima = require 'esprima'
escodegen = require 'escodegen'
fs = require 'fs'
estraverse = require('estraverse')
source = process.argv[2]
fs.readFile source, (err, origCode) ->
logger = esprima.parse(
'console.log("trace: " + arguments.callee.name, arguments);'
@kumabook
kumabook / gist:fa2e5086512244a79876
Created May 27, 2014 02:18
Simple static web server with coffee script
http = require 'http'
fs = require 'fs'
url = require 'url'
path = require 'path'
port = process.argv[2] || 8888;
mime =
".html": "text/html",
".css" : "text/css",
".js" : "application/javascript",
@kumabook
kumabook / a_magic_trick.cpp
Created April 14, 2014 14:48
2014 code jam qulification round problem A
#include <cstdio>
#include <algorithm>
#include <cassert>
using namespace std;
int main()
{
int count;
scanf("%d", &count);
@kumabook
kumabook / file0.txt
Created April 8, 2014 13:53
JavaScriptでDOMツリーの要素を数えあげる ref: http://qiita.com/kumabook/items/6d3e48108029f309ebbd
var DOMTreeUtil = (function() {
var visitAll = function(root, func) {
_visit(root, func);
};
var _visit = function(elem, func) {
if (!elem.hasChildNodes) return;
var i, l;
var child = elem.childNodes;
for (i = 0, l = child.length; i < l; i++) {
func(child[i]);