Instantly share code, notes, and snippets.

View gist:444eb6ecba89405920c2
<?php
/**
* Example: php file.php 6 "1"
*/
class Rec {
protected $grid = [];
protected $fourDirectionMap = [[0, 0], [1, 0], [1, 1], [0, 1]];
View main.go
package main
import (
"fmt"
"math"
"sync"
)
type Matrix struct {
matrix [][]int
View encryption.php
<?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
View callback_generator.js
/**
* 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}
*/
View rods.js
'use strict';
var prices = {
1: 1,
2: 5,
3: 8,
4: 9,
5: 10,
6: 17,
7: 17,
View AppCtrl.go
package controllers
import (
"github.com/revel/revel"
"gopkg.in/mgo.v2"
)
type AppCtrl struct {
*revel.Controller
mongoSession *mgo.Session
View gist:ea0dfe58d77a6774ca23
"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
View gist:7f7976ea9448c68c3673

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.

View sudoku.cpp
#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;
View pegs.py
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)