Skip to content

Instantly share code, notes, and snippets.

View itarato's full-sized avatar

Peter Arato itarato

  • Montreal, Canada
View GitHub Profile
@itarato
itarato / gist:444eb6ecba89405920c2
Created September 13, 2014 23:17
Regular expression image generation
<?php
/**
* Example: php file.php 6 "1"
*/
class Rec {
protected $grid = [];
protected $fourDirectionMap = [[0, 0], [1, 0], [1, 1], [0, 1]];
@itarato
itarato / main.go
Last active August 29, 2015 14:06
Go script to generate base matrix for regex based images
package main
import (
"fmt"
"math"
"sync"
)
type Matrix struct {
matrix [][]int
@itarato
itarato / encryption.php
Created September 28, 2014 18:57
PHP AES CBC encryption then MAX example
<?php
$method = MCRYPT_RIJNDAEL_128;
$block_cypher_mode = MCRYPT_MODE_CBC;
$clean = "Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed molestie augue sit amet leo consequat posuere. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Proin vel ante a orci tempus eleifend ut et magna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus luctus urna sed urna ultricies ac tempor dui sagittis. In condimentum facilisis porta. Sed nec diam eu diam mattis viverra. Nulla fringilla, orci ac euismod semper, magna diam porttitor mauris, quis sollicitudin sapien justo in libero. Vestibulum mollis mauris enim. Morbi euismod magna ac lorem rutrum elementum. Donec viverra auctor lobortis. Pellentesque eu est a nulla placerat dignissim. Morbi a enim in magna semper bibendum. Etiam scelerisque, nunc ac egestas consequat, odio nibh euismod nulla.";
$keyOriginal = "abcdefghijklmop";
$encrypted = encrypt($clean, $keyOriginal, 16, $me
@itarato
itarato / callback_generator.js
Created October 16, 2014 10:53
Paramerized callback generator.
/**
* Parameterized callback generator.
*
* @param callback
* The callable function to call.
* @param ...
* All additional parameters will be arguments of the callback, as well as the default callback arguments:
* Structure: callback(givenArg1, ..., givenArgN, callbackArg1, ..., callbackArgM);.
* @returns {Function}
*/
@itarato
itarato / rods.js
Created November 8, 2014 01:18
Rods
'use strict';
var prices = {
1: 1,
2: 5,
3: 8,
4: 9,
5: 10,
6: 17,
7: 17,
@itarato
itarato / AppCtrl.go
Created November 10, 2014 23:10
Simple controller backed up with MongoDB support.
package controllers
import (
"github.com/revel/revel"
"gopkg.in/mgo.v2"
)
type AppCtrl struct {
*revel.Controller
mongoSession *mgo.Session
@itarato
itarato / gist:ea0dfe58d77a6774ca23
Created November 24, 2014 11:42
Property chain check
"use strict";
/**
* Verify if all sub properties exist of an object.
*
* @example
* For example to verify if window.class.foo.bar.x exist:
* propertyChainExist(window, ['class', 'foo', 'bar', 'x']);
*
* @param object

Analysis of title property loads in Drupal

Task: load title of node

Count: 1'000 (nodes)

The measurement happens on a (close to) clean Drupal 7.34 install. Each iteration started with a clear cache - which can be observed where caching is available and first call is much worse. There are 10 different scenarios:

Note: means and medians are only for times, as memory consumptions are constant through iterations.

@itarato
itarato / sudoku.cpp
Created December 29, 2014 15:09
Sudoku maps - all, sorted
#include <iostream>
#include <vector>
#include <cmath>
#define SUDOKU_SIZE 9
#define COORD_2_IDX(a, b) (SUDOKU_SIZE * a + b)
#define IDX_2_COORD_I(a) (floor(a / SUDOKU_SIZE))
#define IDX_2_COORD_J(a) (a % SUDOKU_SIZE)
using namespace std;
@itarato
itarato / pegs.py
Created January 2, 2015 07:45
3 pegs
import sys
def solve(pegs, pfrom, pto, n):
if n == 1:
pegs[pfrom] -= 1
pegs[pto] += 1
print('{:d}->{:d}'.format(pfrom + 1, pto + 1))
elif n > 1:
solve(pegs, pfrom, third_peg(pfrom, pto), n - 1)