Skip to content

Instantly share code, notes, and snippets.

View st98's full-sized avatar

st98 st98

View GitHub Profile
@st98
st98 / p.py
Last active August 29, 2015 14:11
Movable Type のアレを JSON にするヤツ、自分用なので動けばいいという感じ。
import json
import os.path
import re
import sys
def parse(prog):
result = []
entry = {}
mkey = None
mvalue = None
@st98
st98 / blog.json
Last active August 29, 2015 14:11
python convert.py -c blog.json x.json とかそういう感じで。https://gist.github.com/st98/846f81d5bd40c22f5079 と組み合わせて使う。アレより適当。
{"title": "ぶろぐー"}
@st98
st98 / coffee.txt
Last active August 29, 2015 14:12
coffee -s -n, coffee -s -t
> python -c "print('console.log do -> 1')" | coffee -s -n
Block
Call
Value "console"
Access "log"
Call
Code
Block
Value "1"
@st98
st98 / bf.coffee
Created December 28, 2014 14:44
CoffeeScript で Brainf*ck のインタプリタ。
class Brainfuck
_parse = (prog) ->
prog.match(/[-+><\.,\[\]]/g)
@run: (prog, input=prompt, output=console.log.bind(console)) ->
_memory = []
_pointer = 0
_pc = 0
_depth = 0
prog = _parse prog
while prog[_pc]
@st98
st98 / String#map.js
Last active August 29, 2015 14:13
String#map。
Object.defineProperty(String.prototype, 'map', {
value: function () {
return Array.prototype.map.apply(this, arguments).join('');
},
enumerable: false,
configurable: true,
writable: false
});
@st98
st98 / swapcase.ml
Last active August 29, 2015 14:13
OCaml 入門。Python の str.swapcase() みたいな。
let swapcase c = match c with
| 'A' .. 'Z' -> Char.lowercase c
| 'a' .. 'z' -> Char.uppercase c
| _ -> c
let swapcase_s s = String.map swapcase s;;
swapcase_s "AbC";; (* => "aBc" *)
@st98
st98 / 4.ml
Last active August 29, 2015 14:13
OCaml 入門。http://try.ocamlpro.com/ の Lesson 4 辺り。
(* 試す *)
let f = function
| [| x; (_, _) |] -> x
| _ -> 0, 0;;
f [| 1, 2; 3, 4 |];; (* => (1, 2) *)
let f = function
| [| x; _ |]::_ -> x
| _ -> 0, 0;;
@st98
st98 / composition.ml
Last active August 29, 2015 14:13
OCaml 入門。
3 |> fun x -> x * 2 |> succ;; (* => 7 *)
succ @@ (fun x -> x * 2) @@ 3;; (* => 7 *)
@st98
st98 / bf2js.coffee
Last active August 29, 2015 14:13
Brainf*ck を JavaScript に変換するヤツ。
parse = (prog) ->
prog = prog.replace /[^><\[\],.+-]/g, ''
if prog.length is 0
return []
c = 0
result = (prog.match /([+]+|[-]+|[>]+|[<]+|.)/g).map (m) ->
if m[0] is '['
c++
@st98
st98 / ip.js
Last active August 29, 2015 14:13
IP アドレスがなんか、こう。
// f(2130706433) === '127.0.0.1';
function f(n) {
return [
(n & 0xff << 24) >> 24,
(n & 0xff << 16) >> 16,
(n & 0xff << 8) >> 8,
n & 0xff
].map(String).join('.');
}