Skip to content

Instantly share code, notes, and snippets.

View k4200's full-sized avatar

Kazuo Kashima k4200

View GitHub Profile
@k4200
k4200 / hamamatsu-rb-58.rb
Created November 11, 2015 11:12
hamamatsu.rb #58 のお題を解いた(Ruby)
# 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])
@k4200
k4200 / gist:3088139
Created July 11, 2012 05:12
Calculate height (or width etc.) of a hidden element
/**
* 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();
@k4200
k4200 / gist:2935406
Created June 15, 2012 08:30
Handling MySQL point type with Squeryl
// 1. Class for MySQL point type
class MySQLPoint(val lat: Double, val lng: Double) {
import MySQLPoint._
override def toString = {
lat.toString() + "," + lng.toString()
}
/**
* Gets a binary representation
@k4200
k4200 / gist:1183377
Created August 31, 2011 11:55
printToFileを使った例
// http://stackoverflow.com/questions/4604237/how-to-write-to-a-file-in-scala
FileUtils.printToFile(tempFile)(writer => {
val it = Source.fromFile(conf).getLines()
for (line <- it) {
startPattern.findFirstIn(line) match {
case Some(_) =>
while (it.hasNext && it.next.length != 0) {}
case _ =>
writer.println(line)
}
@k4200
k4200 / fizzbuzz.scala
Created July 13, 2011 11:09
FizzBuzz
(1 to 100)foreach{x=>println(if(x%15>0)if(x%5>0)if(x%3>0)x else"Fizz"else"Buzz"else"FizzBuzz")}
@k4200
k4200 / MegaCRUDify.scala
Created July 10, 2011 09:20
A trait that modifies CRUDify a bit
// This file is distributed under the same license as that of Lift.
package com.example
package lib
import net.liftweb.mapper._
import net.liftweb.common._
import net.liftweb.http.S
trait MegaCRUDify[KeyType, CrudType <: KeyedMapper[KeyType, CrudType]]
@k4200
k4200 / AdminEditableCRUDify.scala
Created July 10, 2011 09:17
A trait that can be mixed in a model that only admin users can do CRUD
// This file is distributed under the same license as that of Lift.
//
package com.example {
package lib {
import net.liftweb._
import common._;
import http._;
import mapper._
import sitemap._;
@k4200
k4200 / gist:1033145
Created June 18, 2011 14:37
Script to create a CSV file for en-ja term dictionary
# -*- coding: utf-8 -*-
# This is my first python script. Whoo hoo!
# I needed to create a csv, each line of which consists of
# key, Japanese text, and English text, out of Java language
# resource files.
import sys
import glob
import re
import csv
@k4200
k4200 / akka-future-example.scala
Created June 11, 2011 00:55
AkkaのサイトにあるFutureの例
// http://akka.io/docs/akka/1.1.2/scala/futures.html
// にあるサンプルコードの説明をコメントとして記入しました。
// 間違い等があれば指摘してもらえればと思います。
// 以下の2行はnon-blockingな処理
val f1 = actor1 !!! msg1 // actor1 に msg1 を投げ、Futureを得る
val f2 = actor2 !!! msg2 // actor2 に msg2 を投げ、Futureを得る
// この時点では actor1, actor2 の処理は終わっていない
@k4200
k4200 / attr-prop.html
Created May 20, 2011 09:09
attr and prop in jQuery 1.6.1
<html>
<script src="jquery-1.6.1.js"></script>
<script type="text/javascript">
function test() {
//FF4で確認。他のブラウザも要チェック
console.log($("#div1"));
console.log($("#div1").prop("val")); //NG
console.log($("#div1").attr("val")); //OK
console.log($("#div1")[0].getAttribute("val")); //OK