Skip to content

Instantly share code, notes, and snippets.

View monzou's full-sized avatar

Takuro Monji monzou

  • Tokyo
View GitHub Profile
@kjaquier
kjaquier / BitSet.java
Last active August 29, 2015 14:01
Enum based and memory efficient flag set.
public class BitSet<T extends Enum<?>> {
private byte[] bytes;
@SafeVarargs
public BitSet(T... elements) {
bytes = new byte[elements.length / 8 + 1];
}
private int bitMask(int ordinal) {
@kozo002
kozo002 / jquery.event-mapping.coffee
Last active August 29, 2015 14:07
Backbone.js like event mapping
jQuery.eventMapping = (object) ->
jQuery.each object.events, (event_and_selector, handler_name) ->
[event, selector_with_elem_name] = event_and_selector.split(' ')
[selector, elem_name] = selector_with_elem_name.split('|')
object.$el.on(event, selector, jQuery.proxy(object[handler_name], object))
if elem_name? then object[elem_name] = object.$el.find(selector)
@mzp
mzp / git-now
Created August 5, 2011 07:47
git-now
#!/bin/sh
PREFIX="from now"
MESSAGE="[${PREFIX}] `date +\"%Y/%m/%d %T\"`"
get_amend() {
if [ -z `git log --pretty=oneline -1 | cut -d " " -f 2- | grep "^\[${PREFIX}]"` ]
then
return 1
fi
@aolshevskiy
aolshevskiy / build.gradle
Created January 16, 2012 03:14
Multiple webapp resource dirs with Gradle-embed Jetty
import org.gradle.api.plugins.jetty.internal.JettyPluginWebAppContext
apply plugin: "jetty"
def newResourceCollection(File... resources) {
shell = new GroovyShell(JettyPluginWebAppContext.class.classLoader)
shell.setProperty("resources", resources as String[])
return shell.evaluate(file("resource_collection.groovy"))
}
import Control.Applicative
-- fmap : (a -> b) -> f a -> f b
-- fmap は関数とファクター値を引数にとって, 関数をファンクター値の中の値に適用
class Functor f where
fmap :: (a -> b) -> f a -> f b
-- <*> : f (a -> b) -> f a -> f b (f is Fanctor)
-- <*> は関数の入っているファンクター値と値の入っているファンクター値を引数にとって, ひとつ目のファンクターの中身の関数をふたつ目のファンクターの中身に適用
@udzura
udzura / fgcs.git.sh
Last active October 7, 2015 10:17
Fxcking git cheet sheet
# stage の操作
git add . # stage に加える
git add -p # stage にインタラクティブに加える
git add -N . # stage にファイルだけ加える
git rm hoge/hoge.rb # stage から消す
git rm -f hoge/hoge.rb # stage から無理矢理消す、先にファイルを消してしまった場合
git mv hoge/hoge.rb hoge/hoge2.rb # ファイル名変える
# 差とか状態を確認する系
git diff # HEADとunstagedの差分を確認する
@alecperkins
alecperkins / gist:4263031
Created December 11, 2012 22:44
CoffeeScript-friendly Backbone.Marionette module definition pattern.
# Since CoffeeScript wraps everything in a closure by default, the module
# definition function pattern that Marionette normally uses is unnecessary.
# (And cumbersome with having to indent everything.) Instead, creating the
# module at the very begining makes it available to everything in the file, and
# the initializers and exported classes can be added at the end of the file.
# (This relies on things like the App and Backbone being on window, but they
# already have to be for CoffeeScript-based code to work.)
# Create the module.
Foo = App.module 'Foo'
@p-j
p-j / Gruntfile.js
Created August 26, 2013 12:37
Gruntfile.js inspired by Yeoman's webapp generated Gruntfiles, with BlessCSS and Assemble, Htmlmin configured to run smoothly with Usemin and Coffee/Mocha stuff commented out.
// Generated on 2013-07-30 using generator-webapp 0.2.6
'use strict';
var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
// # Globbing
// for performance reasons we're only matching one level down:
@ryo-murai
ryo-murai / querydsl-sql.md
Created September 18, 2012 08:56
QueryDsl-SQL概要

QueryDsl-SQL

はじめに

  • QueryDslは、Open Sourceのライブラリ。クエリを型安全で流れるようなインタフェースDSL (Java内部DSL)で記述することができるライブラリで、JPAのCriteria APIに変換するDSLと、直接SQLに変換するDSLとがある。
  • JPAの方については、QueryDslのBlog記事を見れば他にいうことはほとんどないので、この記事ではSQLの方について書く。
  • この記事の執筆時点のバージョンはQueryDsl 2.7.2

基本的な使い方

  • QueryDsl-SQLが提供する antタスク com.mysema.query.sql.ant.AntMetaDataExporter を用いると、データベーススキーマから Java Beanとメタクラスを生成してくれる。今回は下記のようなリレーションをもつBeanを生成した前提の例である。
@brenes
brenes / info_boxes_wikpiedia_regexp.rb
Created September 8, 2011 13:30
Removing infoboxes from Wikipedia pages with a regexp
# INFO extracted from : http://stackoverflow.com/questions/6331065/matching-balanced-parenthesis-in-ruby-using-recursive-regular-expressions-like-pe
require 'wikipedia'
wikipage = Wikipedia.find(title)
# This regular expression is not valid for infoboxes with '}' (i.e: http://en.wikipedia.org/wiki/The_Royal_Anthem_of_Jordan)
no_infoboxes = wikipage.content.gsub(/\{\{[^\}]*\}\}/, "")
# This regular expression makes use of recursive regular expressions so now handles recursive {{}} structures
no_infoboxes = wikipage.content.gsub(%r{(?<re>\{\{(?:(?> [^\{\}]+ )|\g<re>)*\}\})}x, "")