Skip to content

Instantly share code, notes, and snippets.

View tex2e's full-sized avatar
🕶️
Ready to engage

Mako tex2e

🕶️
Ready to engage
View GitHub Profile
@tex2e
tex2e / brainfuck.swift
Created August 13, 2017 02:38
convert brainfuck to swift
let datasize = 65536
var framework = "Darwin"
#if os(Linux)
framework = "Glibc"
#endif
let bf2swift:[Character:String] = [
">": "sp += 1",
"<": "sp -= 1",
@tex2e
tex2e / sample.sh
Last active August 21, 2017 09:20
コマンド実行時に標準入力が与えられているか調べる
#!/bin/bash
if [ ! -p /dev/stdin ]; then
echo "no stdin data" 1>&2
exit 1
fi
# ...
exit 0
@tex2e
tex2e / sample.py
Last active August 17, 2017 12:03
Raspberry Pi の LED 点滅
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
port = 2
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(port, GPIO.OUT)
@tex2e
tex2e / main.lisp
Created August 20, 2017 12:59
A simple database (Lisp)
(defvar *db* nil)
(defun dump-db ()
(dolist (cd *db*)
(format t "~{~a:~10t~a~%~}~%" cd)))
(defun save-db (filename)
(with-open-file (out filename
:direction :output
@tex2e
tex2e / lifegame.lisp
Created August 23, 2017 13:38
Lifegame in Lisp
(setf *random-state* (make-random-state t))
(defun main()
(defvar height 20)
(defvar width 40)
(defvar field (make-array `(,height ,width) :initial-contents
(loop for i from 0 below height collecting
(loop for j from 0 below width collecting (random 2)))))
(loop
@tex2e
tex2e / awaitDOMContentLoaded.js
Last active September 28, 2017 03:15
Resolve promise when document onload
// Resolve promise when document onload
function awaitDOMContentLoaded() {
return new Promise(function (resolve) {
if (document.readyState === "complete") {
resolve();
} else {
document.addEventListener("DOMContentLoaded", resolve);
}
});
@tex2e
tex2e / gamepad-example.js
Created September 28, 2017 03:15
Using all gamepad button infomation
'use strict';
window.addEventListener("gamepadconnected", function(e) {
var gp = e.gamepad;
console.log("gamepad" + gp.index + " is connected!");
}, false);
window.addEventListener("gamepaddisconnected", function(e) {
var gp = e.gamepad;
console.log("gamepad" + gp.index + " is disconnected!");
@tex2e
tex2e / beautify.js
Created October 22, 2017 09:38
turns 9999999 into 9,999,999
// turns 9999999 into 9,999,999
function beautify(num) {
var str = '';
if (!isFinite(num)) return 'Infinity';
if (num.toString().indexOf('e') != -1) return num.toString();
num = Math.round(num * 10000000) / 10000000; // get rid of weird rounding errors
num = Math.floor(num);
num = (num + '').split('').reverse();
for (var i in num) {
@tex2e
tex2e / rand.js
Created October 28, 2017 10:31
random number in range
function rand(min, max) {
if (max === undefined) { max = min; min = 0; }
return Math.floor(Math.random() * (max - min + 1)) + min;
}
@tex2e
tex2e / shuffle.js
Created October 28, 2017 10:33
shuffle array
function rand(min, max) {
if (max === undefined) { max = min; min = 0; }
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function shuffle(array) {
var sample = array.slice(0);
var length = sample.length;
var last = length - 1;