Skip to content

Instantly share code, notes, and snippets.

View masahitojp's full-sized avatar
🎯
Focusing

Masato Nakamura masahitojp

🎯
Focusing
View GitHub Profile
@mooz
mooz / self.js
Created September 10, 2010 07:12
self
var global = this;
global.__defineGetter__("self", function _() {
return _.caller || global;
});
function foo() {
alert(self);
}
@paulsmith
paulsmith / echo.go
Created January 12, 2011 06:09
A simple echo server testing a few interesting Go language features, goroutines and channels.
// $ 6g echo.go && 6l -o echo echo.6
// $ ./echo
//
// ~ in another terminal ~
//
// $ nc localhost 3540
package main
import (
@btompkins
btompkins / Fabric-UserSetup.py
Created February 7, 2011 18:15
Simple fabric function to create a new user
def new_user(admin_username, admin_password):
env.user = 'root'
# Create the admin group and add it to the sudoers file
admin_group = 'admin'
runcmd('addgroup {group}'.format(group=admin_group))
runcmd('echo "%{group} ALL=(ALL) ALL" >> /etc/sudoers'.format(
group=admin_group))
# Create the new admin user (default group=username); add to admin group
@gakuzzzz
gakuzzzz / gist:961416
Created May 8, 2011 15:01
anormの拡張
import play.db.anorm._
import play.db.anorm.defaults._
trait Identifiable[A] {
type ID = A
val id: Pk[ID]
}
trait ExMagic[A <: Identifiable[_]] extends Magic[A] {
@yatsuta
yatsuta / gist:1047733
Created June 26, 2011 16:02
Lisp by R
opt <- options(warn=-1)
## ------------------------------------------------------------
## Test
## ------------------------------------------------------------
## > rm(list=ls()); source("Eval.R")
## > repl()
## rlisp > (<- make.counter (function (c) (function () (<<- c (+ c 1)))))
@xuwei-k
xuwei-k / あんふぃるたー丼.md
Created September 16, 2011 04:40
build.sbt を DRY に書く方法

build.sbt って、かならず settingの値 じゃないといけないから、

val UnfilteredVersion = "0.5.0"

っていう行を定義できないけれど、こんな風 ↓ に書けば DRY に書けるね!っていう、超細かいどーでもいいテクニック !

Some("net.databinder","0.5.0").map{case (a,v) =&gt;
@kmizu
kmizu / Generator.scala
Created September 24, 2011 08:27
Yet another "generator" library implementation in Scala.
//To compile this, "-P:continuations:enable" option is needed.
import scala.util.continuations._
import scala.collection._
object Generator {
abstract sealed class Computation[+A]
case class Yielded[A](k: Unit => Computation[A], v: A) extends Computation[A]
case object Done extends Computation[Nothing]
type yieldable[A] = cps[Computation[A]]
@komamitsu
komamitsu / myecho.ml
Created November 13, 2011 14:14
a Lwt echo server for practice
(* ocamlfind c -w A -linkpkg -package lwt,lwt.unix,lwt.syntax -syntax camlp4o,lwt.syntax myecho.ml -o myecho *)
(* This code refers to https://github.com/avsm/ocaml-cohttpserver/blob/master/server/http_tcp_server.ml *)
open Lwt
let server_port = 12345
let so_timeout = Some 20
let backlog = 10
let try_close chan =
catch (fun () -> Lwt_io.close chan)
@bellbind
bellbind / ecc.py
Created December 1, 2011 08:08
[python]basics of elliptic curve cryptography
# Basics of Elliptic Curve Cryptography implementation on Python
import collections
def inv(n, q):
"""div on PN modulo a/b mod q as a * inv(b, q) mod q
>>> assert n * inv(n, q) % q == 1
"""
for i in range(q):
if (n * i) % q == 1:
@seratch
seratch / build.sbt
Created March 8, 2012 03:06
Using Anorm 2.0 without Play Framework
scalaVersion := "2.9.1"
resolvers += "typesafe" at "http://repo.typesafe.com/typesafe/releases"
libraryDependencies ++= Seq(
"play" %% "anorm" % "2.0-RC4",
"com.github.seratch" %% "scalikejdbc" % "[0.5,)",
"org.hsqldb" % "hsqldb" % "[2,)"
)