Skip to content

Instantly share code, notes, and snippets.

View Sergic's full-sized avatar

Sergey Gerdel Sergic

View GitHub Profile
@Sergic
Sergic / CarQueryAPI.php
Created May 27, 2017 08:31 — forked from bboer/CarQueryAPI.php
CarQueryAPI Sample CLass for PHP
<?php
/**
* Sample implementation fo the CarQueryAPI Json database
*/
class CarQueryAPI
{
/**
* @var string Url to the CarQueryAPI database
*/
protected $apiUrl = 'http://www.carqueryapi.com/api/0.3/?cmd=';
@Sergic
Sergic / Menu.scala
Last active May 8, 2017 18:53
Scala menu builder
case class MenuItem(name: String, uri: Option[String], title: String, parent: Option[MenuItem], submenus: Seq[MenuItem] = Seq.empty[MenuItem], access: Seq[Role]) {
def isGranted(role: Role) = access.contains(role)
def isCurrent(currentUri: String) = uri.contains(currentUri)
def addChild(item: MenuItem): MenuItem = copy(submenus = (submenus :+ item).map(_.addParent(this)))
def addParent(item: MenuItem) = copy(parent = Some(item))
}
@Sergic
Sergic / Morphism.scala
Created November 25, 2016 16:10 — forked from davydkov/Morphism.scala
Scala morphism with shapeless
import shapeless._
import shapeless.labelled._
import shapeless.ops.record.Merger
import shapeless.syntax.SingletonOps
import scala.annotation.implicitNotFound
import scala.collection.generic.CanBuildFrom
import scala.language.experimental.macros
import scala.language.higherKinds
@Sergic
Sergic / start-nb.sh
Last active January 12, 2016 17:16
Start docker machine with mount widows dir
#!/bin/bash
trap '[ "$?" -eq 0 ] || read -p "Looks like something went wrong... Press any key to continue..."' EXIT
VM=nb
DOCKER_MACHINE=./docker-machine.exe
#mount data
SHARE_NAME=projects
SHARE_PATH=c:\\home\\projects
@Sergic
Sergic / Apriori.java
Last active August 29, 2015 14:24 — forked from monperrus/Apriori.java
import java.io.*;
import java.util.*;
/** The class encapsulates an implementation of the Apriori algorithm
* to compute frequent itemsets.
*
* Datasets contains integers (>=0) separated by spaces, one transaction by line, e.g.
* 1 2 3
* 0 9
* 1 9
<?php
//function build tree --- recursive
function show_tree( &$data, $point, $str ){
//reset($data);
$str .= "&nbsp;&nbsp;&nbsp;";
while ( list( $index, $point_data ) = each( $data ) ){
if ( $point_data[ 'parent_id' ] == $point ){
echo $str.$point_data[ 'name' ].'<br>';
unset( $data[ $index ] );
<?php
/**
* Please be aware that private properties are private for good purpose,
* changing it during runtime so is only OK during Unit Testing for example.
* So use this only if you're knowing what you're doing :)
*/
class BareDemoClass() {
VERSION=0.20.6
sudo apt-get update
sudo apt-get install openjdk-6-jdk
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-$VERSION.deb
sudo dpkg -i elasticsearch-$VERSION.deb
# be sure you add "action.disable_delete_all_indices" : true to the config!!
<?php
$collection = new Doctrine\Common\Collection\ArrayCollection();
// add objects to the collection that contain a getCreated method returning a DateTime instance
$iterator = $collection->getIterator();
$iterator->uasort(function ($first, $second) {
if ($first === $second) {