Skip to content

Instantly share code, notes, and snippets.

View k4200's full-sized avatar

Kazuo Kashima k4200

View GitHub Profile
@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();
@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
@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 / 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 / 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._;