Skip to content

Instantly share code, notes, and snippets.

View dorentus's full-sized avatar
🎲
🌎🌍🌏

ZHANG Yi dorentus

🎲
🌎🌍🌏
View GitHub Profile
@dorentus
dorentus / build_config.rb
Last active August 31, 2020 01:53
Put build_config.rb into mruby root dir, make, and put build_framework.rb into build dir and run it to get a MRuby.framework, run collect_mrb_gem_archive.rb <gem_name> in build dir to get a seperate <gem_name>.framework
MRuby::Build.new do |conf|
toolchain :clang
conf.gembox 'default'
end
def crossbuild_for(name, platform, sysroot, cc_defines = [])
MRuby::CrossBuild.new(name) do |conf|
toolchain :clang
conf.gembox 'default'
MRuby::GemBox.new do |conf|
conf.gem :github => 'iij/mruby-digest'
conf.gem :github => 'iij/mruby-io'
conf.gem :github => 'iij/mruby-socket'
conf.gem :github => 'iij/mruby-regexp-pcre'
conf.gem :github => 'iij/mruby-pack'
conf.gem :github => 'dorentus/mruby-bnet-authenticator'
end
class BinaryTree
constructor: () ->
class BinaryTreeNode extends BinaryTree
constructor: (@value, @left, @right) ->Object.freeze(@)
isEmpty: () -> false
depth: () -> 1 + Math.max(@left.depth(), @right.depth())
count: () -> 1 + @left.count() + @right.count()
inorder: (fn) -> @left.inorder(fn); fn(@value); @right.inorder(fn)
String.prototype.bytes = function () {
var bytes = [], i = 0;
while ( true ) {
var byte = this.charCodeAt(i);
if ( isNaN(byte) ) break;
bytes.push(byte);
i += 1;
}
return bytes;
}
interpret = (code) ->
class Machine
constructor: -> @stack = []
push: (v) -> @stack.push(v)
pop: -> @stack.pop()
top: -> @stack[@stack.length - 1]
@dorentus
dorentus / befunge.js
Last active January 19, 2016 19:14
yet another befunge interpreter
function interpret(code) {
var machine = (function () {
var stack = [];
return {
push: function (v) {
stack.push(v);
return this;
},
pop: function () {
@dorentus
dorentus / bf.js
Last active August 29, 2015 13:57
yet another brainfuck interpreter
function brainLuck(code, input){
code = code || '';
input = input || '';
var memory = (function () {
var storage = [], cursor = 0;
return {
read: function () {
return storage[cursor] || 0;
},
write: function (c) {
@dorentus
dorentus / ramdish.sh
Last active February 9, 2017 08:19
ramdisk.sh
#!/bin/bash
RD=ramdisk
if [ ! -e "/Volumes/$RD" ]; then
diskutil erasevolume HFS+ "$RD" `hdiutil attach -nomount ram://16777216` # 8G
# ~/Library/Developer/Xcode
mkdir -p "/Volumes/$RD/Xcode"
@dorentus
dorentus / auto-hostname
Created February 8, 2014 06:03
/etc/network/if-up.d/auto-hostname
#!/bin/sh
set -e
fqdn=$(dig -x `/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'` +noall +answer | grep PTR | awk '{print $5}')
fqdn=${fqdn%.}
if [ -z $fqdn ]; then
exit 0
fi
@dorentus
dorentus / include.d~common-basedir
Created December 12, 2013 09:07
NGINX configurations
#
# $BASE_DIR = case $http_host
# when "a.example.com"
# "a.example.com"
# when "a.b.example.com"
# "b.example.com"
# end
#
set $BASE_DIR $http_host;
if ($http_host ~* ^([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-]+\.[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-]+)$) {