Skip to content

Instantly share code, notes, and snippets.

View gotohr's full-sized avatar
ℹ️
🌳 🧭 ⛺ 🌲

gotohr

ℹ️
🌳 🧭 ⛺ 🌲
View GitHub Profile
@gotohr
gotohr / symfony2_console_demo.php
Created March 13, 2012 09:33
symfony2 console application demo (with class loader, using Console component independently)
<?php
require_once 'Symfony/Component/ClassLoader/UniversalClassLoader.php';
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony' => __DIR__.'/../_libs'
));
$loader->register();
@gotohr
gotohr / gist:7005197
Created October 16, 2013 09:36
declarative function composition - golang
package main
import "fmt"
type F func(i int) int
func (f F) compose(inner F) F {
return func(i int) int { return f(inner(i)) }
}
@gotohr
gotohr / gist:7005203
Last active December 25, 2015 16:19
declarative function composition - PHP
<?php
use \Closure;
class Invokable {
private $closure;
public function __construct(Closure $closure) {
$this->closure = $closure;
}
@gotohr
gotohr / gist:109532bdd60bb6de717b
Created June 18, 2014 10:21
ExtJS 3.4 XTemplate with nested data
var data = [
{ id: 1, subdata: { x: 10, y: 20 } },
{ id: 2, subdata: { x: 20, y: 30 } }
];
var tpl = new Ext.XTemplate([
'<tpl for=".">',
'<p>ID: {id}</p>',
'<tpl for="subdata">',
'<div style="margin-left: 10px">',
@gotohr
gotohr / gist:9be3a4a2c26604a12473
Last active August 29, 2015 14:03
generate all combinations of sets of interface{} sets
package main
import "fmt"
type Set []interface{}
func Combinations(s []Set) Set {
lens := make([]int, len(s))
length := 1
for i, v := range s {
@gotohr
gotohr / gist:fc9d17e8c03675e8539d
Created May 26, 2015 20:05
php dot string to tree
<?php
$map = array(
'person.firstname' => 'John',
'person.lastname' => 'Doe',
'gender' => 'male',
'some.arbitrary.structure.key' => 'smthng'
);
function tree($map) {
@gotohr
gotohr / gist:fc485a458fe19fca71cd
Last active February 14, 2016 17:24
chess jumper problem - find shortest path from A to B
case class Position(x:Int, y:Int) {
def posibleMove(p:Position) = Position(this.x + p.x, this.y + p.y)
def distance(p:Position) = {
Math.sqrt(
Math.pow(Math.abs(p.x - this.x).toDouble, 2)
+ Math.pow(Math.abs(p.y - this.y).toDouble, 2)
)
}
def equal(p: Position) = this.x == p.x && this.y == p.y
def oddCase(t: Position) = {
@gotohr
gotohr / fastping.go
Created May 4, 2020 09:21
github.com/tatsushid/go-fastping example
package main
import (
"fmt"
"net"
"os"
"time"
"github.com/tatsushid/go-fastping"
)
@gotohr
gotohr / mountiso.sh
Created July 1, 2023 15:06
linux cli mount/unmount iso file
sudo mkdir /media/iso
sudo mount -o loop path/to/file.iso /media/iso
#sudo umount /media/iso