Skip to content

Instantly share code, notes, and snippets.

View k4200's full-sized avatar

Kazuo Kashima k4200

View GitHub Profile
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 {
@k4200
k4200 / gist:c26ba194c9ff6e1343e7
Created September 22, 2014 02:07
コンパイルが通らない
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]]
@k4200
k4200 / traversetree.scala
Last active August 29, 2015 14:19
再帰を使って木構造をたどる
// 頭が慣れていないので、再帰むずい
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))
@k4200
k4200 / pre-commit
Created July 17, 2015 14:32
pre-commit that executes php-cs-fixer for the committed files
#!/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
@k4200
k4200 / TwitterProtoUser.scala
Created January 15, 2011 08:46
A trait for Lift framework that enables users to authenticate with Twitter.
/**
* Copyright Kazuo KASHIMA 2011
* k4200 [at] kazu [dot] tv
* Licensed under the same license as Lift framework (Apache 2.0)
*/
package code.model
import net.liftweb._
import mapper._
@k4200
k4200 / gist:807923
Created February 2, 2011 16:19
Extending CRUDify, but this won't compile...
/**
* コンパイル通りません。
*
* やりたい事:
* 1. ProtoUserクラスを継承した任意のクラス(仮にUser)と、モデルクラス(Foo)の2つが存在。
* 2. Fooには、どのユーザーがレコードを作成したかを表すフィールドがあり、Userテーブルへの外部キーとなっている。
* 3. レコードの所有者のみがCRUDの機能を使えるよう。
* 4. 2, 3の機能はtraitにして、Foo以外のクラスでも同様の機能を使えるようにしたい。
*
* Liftのソースをにらめっこしながら頑張ったんだけど・・・
@k4200
k4200 / AggregateFunctions.scala
Created February 10, 2011 05:21
Aggregate functions for Lift MetaMapper
/**
* Copyright Kazuo KASHIMA 2011
* k4200 [at] kazu [dot] tv
* Licensed under the same license as Lift framework (Apache 2.0)
*/
// Some methods used here are private[mapper], so I need to put these traits
// under net.liftweb.mapper.
package net.liftweb {
package mapper {
@k4200
k4200 / gist:879070
Created March 21, 2011 05:14
crypt in Ruby
irb(main):002:0> "1234567890".crypt("AA")
=> "AAOytELTtvgVU"
irb(main):003:0> "1234567809".crypt("AA")
=> "AAOytELTtvgVU"
irb(main):004:0> "1234567809".crypt("$1$AA")
=> "$1$AA$FGGqw9MVpWh4jOox/NNHk0"
irb(main):005:0> "1234567890".crypt("$1$AA")
=> "$1$AA$GpKPiWMTtFX2jcBN5zP7v1"
@k4200
k4200 / gist:946845
Created April 28, 2011 17:43
inheritance or mix-in?
// There's a class called MappedPassword in Lift. I wanted to create a class that
// holds the plain text when a password is set.
//-------------------------------
// This works, but I didn't like the idea for two reasons.
// 1. The class name is long.
// 2. Seems kinda ugly to me.
abstract class MappedPasswordWithPlainWhenSet[A<:Mapper[A]](override val fieldOwner: A)
extends MappedPassword[A](fieldOwner) {
var plain: String = ""
<form name="aa" action="foo.php" method="POST">
<input type='text' name='important_info' />
<input type='hidden' name='token' value='<?php echo session_id(); ?>' />
<input type='submit' name='submit' value='send it' />
</form>
-----
<!-- 次のページ foo.php -->
<?php
session_start();