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
}
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])
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
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))
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]]
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 {
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
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 <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
View scraping-yql.html
<html>
<header>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="/javascripts/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var url = "http://example.com/";
var query = 'select * from html where url="' + url + '" and xpath="*"';
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();