Skip to content

Instantly share code, notes, and snippets.

@SamuraiT
SamuraiT / json.py
Created July 13, 2014 06:23
json converter example
#import json
#dic = json.loads(json_data)
dic = {'title':'pypy', 'egg':'spam', 'id':'4'}
_map = {'title':
{'name':'title',
'func':lambda val:str(val)},
'egg':
{'name':'spam',
'func':lambda val:str(val)},
python -c 'import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer(("127.0.0.1", 8888), shs.SimpleHTTPRequestHandler).serve_forever()'
@SamuraiT
SamuraiT / example.py
Last active August 29, 2015 14:07
example_of_RedBlue
>>> from RedBlue import Event
>>> f = open('RedBlue/flask.html')
>>> events = Event(f)
>>> events #イベント情報が複数ある場合を考慮し,イベントインスタンスのリストを返す
[<Event:0>]
>>> e = events[0]
>>> e.place #開催場所
'旭川市'
>>> e.date #開催日
datetime.datetime(2013, 11, 10, 0, 0)
@SamuraiT
SamuraiT / docker.md
Created November 13, 2014 10:14
docker

https://docs.docker.com/introduction/understanding-docker/#what-are-the-major-docker-components

Docker helps you ship code faster, test faster, deploy faster, and shorten the cycle between writing code and running code. Docker does this by combining a lightweight container virtualization platform with workflows and tooling

At its core, Docker provides a way to run almost any application securely isolated in a container.

Surrounding the container virtualization are tooling and a platform which can help you in several ways:

@SamuraiT
SamuraiT / parse.py
Last active August 29, 2015 14:11
lisp interpreter for arithmetic operations
def read_from_tokens(tokens):
if len(tokens) == 0: raise SyntaxError("unexpected EOF while reading")
token = tokens.pop(0)
if token == '(':
L = []
while tokens[0] != ')':
L.append(read_from_tokens(tokens))
print(L)
tokens.pop(0) # pop off ')'
return L
@SamuraiT
SamuraiT / env.py
Last active August 29, 2015 14:11
Environment for simple lisp
Env = dict
def starndard_env():
import operator as op
env = Env()
env.update({
'+': op.add,
'-': op.sub,
'*': op.mul,
'/': op.truediv,
@SamuraiT
SamuraiT / eval.py
Last active August 29, 2015 14:11
evaluation for simple lisp interpreter
def eval(x, env=global_env):
if isinstance(x, Symbol):
return env[x]
elif not isinstance(x, List):
return x
else:
proc = eval(x[0], env)
args = [eval(arg, env) for arg in x[1:]]
return proc(*args)
@SamuraiT
SamuraiT / repl.py
Created December 10, 2014 00:51
simple REPL
def repl(prompt="(scheme)> "):
while True:
val = eval(parse(input(prompt)))
if val is not None:
print(val)
@SamuraiT
SamuraiT / simple_lisp_interpreter.py
Created December 10, 2014 00:57
simple lisp interpreter
# coding: utf-8
Env = dict
Symbol = str
List = list
Number = (int, float)
def tokenize(chars):
return chars.replace('(', ' ( ').replace(')', ' ) ').split()
#! /usr/bin/env python
# coding: utf-8
"""
Copyright 2014 Tatsuro Yasukawa.
Distributed under the GNU General Public License at
gnu.org/licenses/gpl.html.
"""
def merge(x,y):