Skip to content

Instantly share code, notes, and snippets.

@zenwerk
zenwerk / firstFollow.ml
Created June 12, 2018 15:55
実践コンパイラ構成法のページのFIRST/FOLLOW集合を導出するプログラム例
let rule1 =
[["Z"; "d"]; ["Z"; "X"; "Y"; "Z"]; ["Y"]; ["Y"; "c"]; ["X"; "Y"]; ["X"; "a"]]
let rule2 =
[ ["S'"; "L"; "$"]
; ["L"; "S"; ";"; "L"]
; ["L"; "S"]
; ["S"; "id"; "="; "E"]
; ["S"; "print"; "("; "E"; ")"]
; ["E"; "T"; "E'"]
@zenwerk
zenwerk / arduino_laser_harp.pde
Created November 3, 2017 16:07
arduino_laser_harp.pde
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// MAKE MAGAZINE - LASER HARP FOR ARDUINO
// Stephen Hobley 2008
// www.stephenhobley.com
////////////////////////////////////////////////////////////////////////////////////////////////////////
// Variables: ///////////////////////////////////////////////////////////////////////////////////////////
#define BEAMCOUNT 6 // レーザーの数
#define MIDICMD_NOTEON 0x90 // MIDIコマンド (Note On, Channel 0)
#define MIDICMD_CTRL 0xb0 // MIDI Controller message - channel 0
@zenwerk
zenwerk / letsencrypt.conf.j2
Created October 10, 2017 17:00
Ansible の LetsEncrypt モジュールを使う
server {
listen 80;
client_max_body_size 20M;
server_name {{ domain }};
location /.well-known/acme-challenge/ {
alias /var/www/letsencrypt/.well-known/acme-challenge/;
try_files $uri =404;
access_log off;
}
@zenwerk
zenwerk / sendmail_with_attachment.go
Last active March 27, 2017 17:18
go / smtp で添付ファイル付きメール送信
package main
import (
"crypto/tls"
"fmt"
"net/mail"
"net/smtp"
"github.com/scorredoira/email"
)
@zenwerk
zenwerk / print_r.lua
Created May 7, 2014 05:07
php like print_r function.
-- from http://lua-users.org/wiki/TableSerialization
function print_r (t, name, indent)
local tableList = {}
function table_r (t, name, indent, full)
local serial=string.len(full) == 0 and name
or type(name)~="number" and '["'..tostring(name)..'"]' or '['..name..']'
io.write(indent,serial,' = ')
if type(t) == "table" then
if tableList[t] ~= nil then io.write('{}; -- ',tableList[t],' (self reference)\n')
@zenwerk
zenwerk / 0_reuse_code.js
Created March 24, 2014 04:03
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
def call_classmethod(*args):
"""
モジュール内のクラスのクラスメソッドを実行しやすくするためのヘルパ関数
args にはメソッドを実行したいclassを指定
"""
current_module = sys.modules[__name__]
factories = {}
results = {}
@zenwerk
zenwerk / class_decorator.py
Created December 11, 2013 16:38
Python Class Decorator
class test(object):
"""A property whose value is computed only once. """
def __init__(self, function):
self._function = function
def __get__(self, obj, _=None):
if obj is None:
return self
value = self._function(obj)
@zenwerk
zenwerk / divide.py
Created September 27, 2013 08:51
与えらた数をバランスよくN分割したリストを返す関数。
# -*- coding:utf-8 -*-
def divide(num, by):
""" num を バランスよく by分割する関数
e,g:num=13, by=2 => [7, 6]
num=30, by=4 => [8, 8, 7, 7]
"""
quotient, rest = divmod(num, by)
ans = [quotient for i in range(by)]
@zenwerk
zenwerk / dump_queryset.py
Created July 23, 2013 09:42
dump django queryset object to yaml
def dump_queryset(qs, format='yaml', indent=2, filename=None):
""" QuerySet をカレントディレクトリにyamlで出力するCLI Utility """
if not isinstance(qs, QuerySet):
raise ValueError(u'QuerySet以外はシリアライズできません')
data = serializers.serialize(format, qs, indent=indent)
if not filename:
model_name = qs[0].__class__.__name__
now_str = datetime.now().strftime('%Y_%M_%d__%H_%M_%S')