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 / mkdo.sh
Last active August 29, 2015 14:19
C言語のコンパイルと実行をまとめて行うスクリプト(bash)
#! /bin/bash
function usage() {
echo "usage: mkdo <file> [-c '<args>'] [-e '<args>'] [-o]"
exit 0
}
if [ $# -eq 0 ]; then
usage
fi
@tex2e
tex2e / sqrt.c
Last active August 29, 2015 14:19
入力された数の平方根を求めるプログラム(c)
#include <stdio.h>
int main(void){
int i;
int root;
double x;
printf("input a number > "); scanf("%d", &root);
x = root;
@tex2e
tex2e / observer.coffee
Last active February 7, 2016 12:17
Observer with CoffeeScript
#
# EventEmitter -- emit event for event-driven programming
#
# All classes which emit event will extend the EventEmitter class
#
class EventEmitter
# private _listeners
#
# All listeners is stored to _listeners.
@tex2e
tex2e / dedent
Created March 21, 2016 12:53
strip indentation for Ruby heredoc
# strip indentation
class String
def dedent
margin = self.scan(/^ +/).map(&:size).min
self.gsub(/^ {#{margin}}/, '')
end
end
@tex2e
tex2e / EventEmitter.min.js
Last active September 25, 2016 07:34
node EventEmitter.min.js
var EventEmitter=function(){function EventEmitter(){this._events=this._events||{};this._maxListeners=this._maxListeners||undefined}EventEmitter.EventEmitter=EventEmitter;EventEmitter.prototype._events=undefined;EventEmitter.prototype._maxListeners=undefined;EventEmitter.defaultMaxListeners=10;EventEmitter.prototype.setMaxListeners=function(n){if(!isNumber(n)||n<0||isNaN(n))throw TypeError("n must be a positive number");this._maxListeners=n;return this};EventEmitter.prototype.emit=function(type){var er,handler,len,args,i,listeners;if(!this._events)this._events={};if(type==="error"){if(!this._events.error||isObject(this._events.error)&&!this._events.error.length){er=arguments[1];if(er instanceof Error){throw er}else{var err=new Error('Uncaught, unspecified "error" event. ('+er+")");err.context=er;throw err}}}handler=this._events[type];if(isUndefined(handler))return false;if(isFunction(handler)){switch(arguments.length){case 1:handler.call(this);break;case 2:handler.call(this,arguments[1]);break;case 3:handler.c
@tex2e
tex2e / doc.md
Last active March 27, 2023 15:49
get all the files from website

get all the files from website

wget -m -p -E -k -K -np http://site/path/

wget will only follow links, if there is no link to a file from the index page, then wget will not know about its existence, and hence not download it. ie. it helps if all files are linked to in web pages or in directory indexes.

@tex2e
tex2e / fibo.exs
Last active March 11, 2017 10:26
Elixir Fibonacci with stream
Stream.unfold({1, 2}, fn {n1, n2} -> {n1, {n2, n1+n2}} end)
|> Enum.take(15)
|> IO.inspect
# => [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]
@tex2e
tex2e / fibo.p6
Created March 11, 2017 10:25
Perl6 Fibonacci
say (1, 2, *+* ... * > 1000);
# => (1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597)
@tex2e
tex2e / calc.py
Last active May 23, 2017 08:10
小町算の +, -, 空白 の三種類バージョンの解き方
# □1□2□3□4□5□6□7□8□9 = 100
# □ = ' ' or '-' or '+'
import sys
for i in range(0, pow(3, 9)):
pattern = [0] * 9
i, pattern[8] = divmod(i, 3)
i, pattern[7] = divmod(i, 3)
@tex2e
tex2e / numcount.c
Created August 12, 2017 23:52
順番処理(名前付きパイプ)
// 標準入力から送られてくるデータのうち、3から9までの数字を抜き出してその都度別々のファイル記述子に出力する
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#define _WITH_DPRINTF
#include <stdio.h>
#include <stdarg.h>