Skip to content

Instantly share code, notes, and snippets.

View datayja's full-sized avatar
:shipit:
Shipping it

Markéta Lisová datayja

:shipit:
Shipping it
View GitHub Profile
<?php
/**
* Gemstone::framework app/lib/utils/inflector.lib.php
*
* Library to provide a framework for various inflections.
*
* @author Pavel Lisa <[email protected]>
* @copyright 2010 Gemstone Webdesign
* @package framework
* @subpackage library
@datayja
datayja / sample_dynamic_finder.php
Created October 13, 2010 15:02
A small example of dynamic finder methods from the Gemstone::framework
<?php
/**
* @author Pavel Lisa <[email protected]>
*
* Requires PHP 5.3+
*/
// get a singleton instance of ActiveRecord\Table
// -> there is one AR\Table instance for each table,
@datayja
datayja / comparer.cpp
Created November 29, 2010 10:26
Sample C++ class implementation of functor/comparer object
#include <string>
template <class T>
struct Comparer
{
Comparer(void){}
~Comparer(){}
// const & - not modifying compared items and not copying them
int operator () (const T & a, const T & b) const
@datayja
datayja / rb_tree.cpp
Created November 29, 2010 14:27
Basic interface for Red-Black tree data structure container in C++
#include <memory>
template <class Type, class Allocator = std::allocator<Type> >
class RB_Tree
{
public:
RB_Tree (void) {}
~RB_Tree () {}
typedef Allocator allocator_type;
<?php
include 'test/test1.php';
echo 'Entry file executed! ';
?>
@datayja
datayja / ruby_vs_cpp_1.cpp
Last active September 25, 2015 22:48
C++ vs. Ruby
#ifdef __cplusplus
#include <iostream>
int main(int argc, const char **argv) {
for (unsigned int i = 0; i < 5; i++) {
std::cout << "Hello!" << std::endl;
}
}
#endif
@datayja
datayja / array_merge_derivation.php
Last active October 11, 2015 03:07
Array merge, derivation style
<?php
function array_merge_derivation (array $base, array $derived)
{
$merged = [];
foreach ($base as $base_key => $base_value) {
$merged[$base_key] = $base_value;
if (isset($derived[$base_key])) {
if (\is_array($base_value)) {
$merged[$base_key] = array_merge_derivation($base[$base_key], $derived[$base_key]);
@datayja
datayja / test.rb
Created November 5, 2012 12:59
Fun with call/cc in Ruby
require "continuation"
$a = 1
def test
$a = callcc do |cc|
$b = cc
puts $a
3
end
end
@datayja
datayja / array_group_by.php
Last active December 16, 2015 09:49
Group by operation implemented in PHP on arrays.
<?php
function array_group_by (array $array, callable $mapping)
{
$buckets = [];
foreach ($array as $item) {
$key = $mapping($item);
if (!isset($buckets[$key])) {
$buckets[$key] = [$item];
} else {
$buckets[$key][] = $item;
@datayja
datayja / ClassObject.php
Last active December 16, 2015 10:39
ClassObject for PHP
<?php
class ClassObject
{
const METHOD_NEW = 'new';
private static $classObjectInstances = [];
private $className;
public static function get ($className)