Skip to content

Instantly share code, notes, and snippets.

View keyvanakbary's full-sized avatar

Keyvan Akbary keyvanakbary

View GitHub Profile

Quick install PHP 7.0:

1. Install depends PHP 7.0
$ brew install autoconf automake gmp homebrew/versions/bison27 gd freetype t1lib gettext zlib mcrypt
2. Configure PHP 7.0
$ git clone --depth=1 https://github.com/php/php-src.git

$ cd php-src

@keyvanakbary
keyvanakbary / object.scm
Created March 13, 2016 20:36
Modelling objects
(define (create-user name)
(define say-hello
(print "Hello " name))
(define (change-name new-name)
(set! name new-name)
name)
(define (dispatch method)
(cond
((eq? method 'say-hello) say-hello)
((eq? method 'change-name) change-name)
@keyvanakbary
keyvanakbary / stateful-accumulator.clj
Created March 13, 2016 20:57
Stateful Accumulator
(defn make-acumulator [value]
(def acc (atom value))
(fn [add]
(swap! acc #(+ % add))
@acc))
(def a (make-acumulator 10))
(a 10)
;20
const cons = (x, y) => (m) => m(x, y);
const car = (z) => z((p, q) => p);
const cdr = (z) => z((p, q) => q);
const pair = cons(1, 2);
console.log(car(pair), cdr(pair));//1 2
const list = cons(1, cons(2, cons(3, cons(4, null))));
const each = (l, fn) => cdr(l) ? (() => {fn(car(l)); each(cdr(l), fn)})() : fn(car(l));
each(list, console.log);//1 2 3 4
public class Solution {
public void traverse(TreeNode root) {
Queue<TreeNode> nodes = new ArrayList();
nodes.add(root);
while (!nodes.isEmpty()) {
TreeNode node = nodes.remove();
System.out.println(node.val);
if (node.left != null) queue.add(node.left);
DROP FUNCTION IF EXISTS lowerword;
DELIMITER |
CREATE FUNCTION lowerword( str VARCHAR(128), word VARCHAR(5) )
RETURNS VARCHAR(128)
DETERMINISTIC
BEGIN
DECLARE i INT DEFAULT 1;
DECLARE loc INT;
SET loc = LOCATE(CONCAT(word,' '), str, 2);