Skip to content

Instantly share code, notes, and snippets.

View spolischook's full-sized avatar
🌐
Saving the world

Serhii Polishchuk spolischook

🌐
Saving the world
View GitHub Profile
<?php
namespace App\Tests;
use App\Calculator;
class CalculatorTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider addProvider
var conn = new Mongo();
db = conn.getDB('dbname');
db.image_fallback.update(
{class: 'Exercise\\BlogBundle\\Document\\Blog'},
{
$set: {
'image.extension': '.png',
'image.thumbnails': []
Array.prototype.cut = function(f) {
var res = [],
i = 0;
while (i < this.length) {
if (f(this[i])) {
res.push(this[i]);
this.splice(i,1);
} else {
i++;
}
@spolischook
spolischook / take_with_guard.hs
Created August 21, 2015 01:22
right implementation take with recursion
take' :: Int -> [Int] -> [Int]
take' x [] = []
take' 0 xs = []
take' x (xx:xxs)
| x <= 0 = []
| otherwise = xx : take' (x-1) xxs
@spolischook
spolischook / take_with_guard.hs
Created August 21, 2015 01:22
right implementation take with recursion
take' :: Int -> [Int] -> [Int]
take' x [] = []
take' 0 xs = []
take' x (xx:xxs) = xx : take' (x-1) xxs
<?php
class UserAdmin extends BaseUserAdmin
{
public function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('dailyActivityLevel', 'choice', [
'choices' => array_map(
function ($string) { return strip_tags($string); },
array_map(function ($string) {return $this->translator->trans($string);}, DailyActivityLevelEnum::getReadables())
@spolischook
spolischook / sprintf.js
Last active November 15, 2015 21:45
sprintf on javascript with recursion
// sprintf('You have %count% new emails from %name%!', [
// ['%count%', user.email.count],
// ['%name%', user.firstName]
// ]);
var sprintf = function(str, replacementList) {
if (typeof(replacementList)==='undefined') replacementList = [];
var replacementTuple = replacementList.shift();
if (replacementTuple)
@spolischook
spolischook / doctrine_migration_sql_sample.php
Last active January 10, 2023 12:06
Complete doctrine sql migration sample
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
public function findByDateRangeAndSlug(\DateTime $fromDate, \DateTime $toDate, $performanceSlug = null)
{
$qb = $this->createQueryBuilder('u')
->WHERE('u.dateTime BETWEEN :from AND :to')
->setParameter('from', $fromDate->format('Y-m-d H:i'))
->setParameter('to', $toDate->format('Y-m-d H:i'))
->orderBy('u.dateTime', 'ASC')
;
if ($performanceSlug) {