Instantly share code, notes, and snippets.

# Kazuo KASHIMAk4200

• Sort options
Created Nov 11, 2015
hamamatsu.rb #58 のお題を解いた（Scala）
View hamamatsu-rb-58.scala
 // http://jukensansu.cocolog-nifty.com/planet/2015/11/post-0b4b.html // parser combinators とか使えそうな気もするけど分からん def arrayToDigit(ary: List[Int]): Int = { ary(0) * 100 + ary(1) * 10 + ary(2) } def calcSum(ary: List[Int]): Int = { List(ary.slice(0, 3), ary.slice(2, 5), ary.slice(4, 7), ary.slice(6, 8) :+ ary(0)).map(arrayToDigit).sum }
Created Nov 11, 2015
hamamatsu.rb #58 のお題を解いた（Ruby）
View hamamatsu-rb-58.rb
 # http://jukensansu.cocolog-nifty.com/planet/2015/11/post-0b4b.html # 総当りで # Rubyはあまり得意でない def array_to_digit(ary) return ary[0] * 100 + ary[1] * 10 + ary[2] end def calc_sum(ary) return array_to_digit(ary[0, 3]) + array_to_digit(ary[2, 3]) + array_to_digit(ary[4, 3]) + array_to_digit(ary[6, 2] + ary[0, 1])
Created Jul 17, 2015
pre-commit that executes php-cs-fixer for the committed files
View pre-commit
 #!/bin/bash # Based on this gist https://gist.github.com/mardix/3623562 while read -r file; do if [[ \$file = *.php ]]; then php-cs-fixer fix "\$file" --fixers=-phpdoc_params,-psr0,-visibility git add "\$file" fi
Last active Aug 29, 2015

View traversetree.scala
 // 頭が慣れていないので、再帰むずい case class Tree(id: Int, children: List[Tree]) val n8 = Tree(8, Nil) val n4 = Tree(4, Nil) val n5 = Tree(5, Nil) val n6 = Tree(6, List(n8)) val n7 = Tree(7, Nil) val n2 = Tree(2, List(n4, n5)) val n3 = Tree(3, List(n6, n7)) val n1 = Tree(1, List(n2, n3))
Created Sep 22, 2014
コンパイルが通らない
View gist:c26ba194c9ff6e1343e7
 abstract class C case class C1() extends C case class C2() extends C trait Service[T <: C] { def getFoo(): Option[T] } object Service { // found : List[Option[Any]]
Created May 9, 2014
View PlaySlickCodeGenerator.scala
 import java.io.File import play.api._ import play.api.Application import play.api.db.slick.Database import scala.slick.model.codegen.SourceCodeGenerator import scala.slick.jdbc.meta.createModel /** */ object PlaySlickCodeGenerator {
Last active Jan 3, 2016
fabfile.py for Play! framework 2.2 multi-project settings.
View fabfile.py
 from fabric.api import local, env, run, roles, execute, put from fabric.utils import abort env.user = "playuser" env.roledefs = { 'web': ['web.example.com'], 'batch': ['batch.example.com'] } env.num_of_releases = 3
Last active Dec 20, 2015
.emacs PHP関連の設定もうちょっと充実させて、ちゃんとバージョン管理する。
View .emacs
 (put 'upcase-region 'disabled nil) (add-to-list 'load-path (expand-file-name "~/.emacs.d/elisp")) (add-to-list 'load-path (expand-file-name "~/.emacs.d/auto-install")) ;; key bindings (global-set-key "\C-c\C-c" 'comment-or-uncomment-region) (global-set-key (kbd "C-x ") 'windmove-up) (global-set-key (kbd "C-x ") 'windmove-down)
Created Apr 3, 2013
Scrape a page by using YQL
View scraping-yql.html

Created Jul 11, 2012
Calculate height (or width etc.) of a hidden element
View gist:3088139
 /** * Based on the following discussion: * http://stackoverflow.com/questions/2345784/jquery-get-height-of-hidden-element-in-jquery * @param jQuery \$elem jQuery object */ function getHeightOfHiddenElem(\$elem) { \$clone = \$elem.clone(); \$clone.css({'position':'absolute','visibility':'hidden','display':'block'}); \$('body').append(\$clone) var height = \$clone.height();