Skip to content

Instantly share code, notes, and snippets.

View keitaoouchi's full-sized avatar

Keita Oouchi keitaoouchi

  • kakaku.com
  • Tokyo
View GitHub Profile
# -*- coding: utf-8 -*-
from collections import Iterator, Sequence, MutableSequence
class MyLinkedList(MutableSequence):
def __init__(self, *value):
'''
>>> l = MyLinkedList(1,2,3)
@keitaoouchi
keitaoouchi / dec2bin.py
Created April 3, 2012 04:30
Convert decimal 2 binary
#!/usr/bin/python
import sys,re
from optparse import OptionParser
def dec2bin(target):
result = []
mask = 1
shift = 0
while mask <= target:
@keitaoouchi
keitaoouchi / fizzbuzz.py
Created April 3, 2012 08:58
fizuubuzz without if/else clause
fizzbuzz = lambda i: ("fizz" * (not i % 3) + "buzz" * (not i % 5)) or str(i)
@keitaoouchi
keitaoouchi / RecursiveListing.scala
Created April 5, 2012 02:39
Recursive directory listings with ignore pattern.
import scala.collection.mutable.Queue
import scala.collection.mutable.ListBuffer
object RecursiveListing {
def main(args: Array[String]) {
val result = listing("/path/to/somewhere", Queue[String](), ListBuffer[String](), ".svn")
print(result.size)
}
@keitaoouchi
keitaoouchi / recursive_listing.py
Created April 5, 2012 02:45
Recursive directory listing with ignore pattern.
import os
def recursive_listing(root, ignoredirs=None, ignorefiles=None):
result = []
ignoredirs = ignoredirs or []
ignorefiles = ignorefiles or []
for dir, subdirs, fnames in os.walk(root):
if all(map(lambda d: d not in dir, ignoredirs)):
for name in fnames:
if all(map(lambda f: f not in name, ignorefiles)):
@keitaoouchi
keitaoouchi / cardComplete.scala
Last active September 16, 2016 16:06
card complete problem implementation -- http://iridge.jp/news/20111220/
object CardComplete {
def main(args: Array[String]) {
val calcargs = inquiry()
//val calcargs = (1000000,15,525)
val start = System.currentTimeMillis
calculate(calcargs._1, calcargs._2, calcargs._3)
val end = System.currentTimeMillis
println("(in %s sec)".format((end - start) / 1000.0))
}
@keitaoouchi
keitaoouchi / gitsvn.py
Last active December 19, 2015 11:19
git-svnでリビジョン番号かチケット番号でデプロイファイルの一覧を出力する
#!/usr/bin/env python3
"""git-svnでリビジョン番号かチケット番号でデプロイファイルの一覧を出力する
python gitsvn.py -d /path/to/repos -r 1 2 3
python gitsvn.py -d /path/to/repos -t 1000
"""
import re
@keitaoouchi
keitaoouchi / ChromeActivity.Swift
Created October 30, 2015 17:48
ChromeActivity.swift
import UIKit
import Foundation
class ChromeActivity: UIActivity {
private var url: NSURL?
static var isAvailable: Bool {
if let chromeURL = NSURL(string: "googlechrome-x-callback://") {
return UIApplication.sharedApplication().canOpenURL(chromeURL)
@keitaoouchi
keitaoouchi / observer.swift
Created January 6, 2016 08:47
Observing notifications from iTunes on OSX
import Cocoa
let nc = NSDistributedNotificationCenter.defaultCenter()
nc.addObserverForName(nil, object: nil, queue: nil) { notification in
if let info = notification.userInfo where notification.name == "com.apple.iTunes.playerInfo" {
print(info)
}
}
NSRunLoop.mainRunLoop().run()
func reverseGeocoding(location: CLLocation) {
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(location) { (placemarks, _) -> Void in
guard let placemarks = placemarks, !placemarks.isEmpty else { return }
if let placemark = placemarks.first {
log.debug(placemark)
}
}
/*