Skip to content

Instantly share code, notes, and snippets.

@takscape
takscape / gist:1266698
Created October 6, 2011 06:46
Scala: ローンパターン1
import collection.JavaConversions._
import java.net.URL
import org.apache.commons.io.IOUtils
object scalatest
{
final class CloseableLike[T1 <: {def close(): Unit}](val a: T1) {
def withClose[T2](f: T1 => T2): T2 = {
try {
f(a)
@takscape
takscape / gist:1267370
Created October 6, 2011 13:15
Scala: ローンパターン2
import collection.JavaConversions._
import java.net.URL
import org.apache.commons.io.IOUtils
object scalatest
{
def closing[T <: {def close(): Unit}, R](a: T)(f: T => R): R = {
try {
f(a)
} finally {
@takscape
takscape / gist:1272336
Created October 8, 2011 14:15
Scala: Esper
import com.espertech.esper.client.{Configuration, EventBean, UpdateListener, EPServiceProviderManager}
import java.util.HashMap
import scala.collection.JavaConversions._
object Sandbox
{
def main(args: Array[String]) {
val config = new Configuration();
val eventType = new HashMap[String, AnyRef]()
eventType.put("itemName", classOf[String])
@takscape
takscape / gist:1274554
Created October 10, 2011 03:08
Scala: Squeryl
import java.sql.DriverManager
import org.apache.commons.io.IOUtils
import org.h2.jdbcx.JdbcDataSource
import org.squeryl.adapters.H2Adapter
import org.squeryl.{KeyedEntity, Session, SessionFactory, Schema}
import scala.collection.JavaConversions._
import org.squeryl.PrimitiveTypeMode._
class User(val id: Long, val name: String) extends KeyedEntity[Long]
@takscape
takscape / gist:1283958
Created October 13, 2011 10:54
Scala: IntelliJ IDEA用build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="scalatest" default="compile" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">
<description>
Scala test code.
</description>
<property name="bin" location="out/production/scalatest"/>
<property name="src" location="src"/>
<property name="lib" location="lib"/>
<property name="version" value="dev"/>
@takscape
takscape / gist:1711078
Created January 31, 2012 15:28
Python: スカパーのチャンネル一覧取得
# -*- coding: utf-8 -*-
import requests
import re
from BeautifulSoup import BeautifulSoup
MASTER_URL = "http://www.skyperfectv.co.jp/search/sky/S5_1/InfoInput.html"
PROGRAM_URL = "http://www.skyperfectv.co.jp/search/sky/S9_1/Program.html"
NAME_EXTRACTOR = re.compile(r'name\s*:\s*"([^"]+)"')
CHANNEL_EXTRACTOR = re.compile(r'chAr\[(\d+)\]\s*=\s*"([^"]+)"')
@takscape
takscape / gist:3505196
Created August 28, 2012 23:13
Encoding Converter
/*
** The author disclaims copyright to this source code.
** In place of a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
*/
/*
** Any feedback would be appreciated.
@takscape
takscape / gist:3697174
Created September 11, 2012 09:24
.erlang example
begin
BaseDir = "C:/opt/erllibs",
lists:foreach(
fun(Dir) ->
Ebin = filename:join([BaseDir, Dir, "ebin"]),
case filelib:is_dir(Ebin) of
true -> code:add_patha(Ebin);
false -> ok
end
end,
@takscape
takscape / gist:4162257
Created November 28, 2012 16:13
Testcase for reproducing issue #123
from aspen import resources, Response
from aspen.resources.negotiated_resource import NegotiatedResource
from aspen.testing import assert_raises, attach_teardown, handle, mk, StubRequest
from aspen.website import Website
from aspen.renderers.tornado import Factory as TornadoFactory
def get(**_kw):
kw = dict( website = Website([])
, fs = ''
@takscape
takscape / gist:4319478
Created December 17, 2012 16:10
A Python writer plugin for collectd
# -*- coding: utf-8 -*-
import collectd
import logging
import time
from logging.handlers import RotatingFileHandler
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
LOGFILE_PATH = "/var/log/collectd/values.log"