Skip to content

Instantly share code, notes, and snippets.

View zemd's full-sized avatar
🇺🇦

Dmytro Zelenetskyi zemd

🇺🇦
  • Ikea IT AB
  • Malmö, Sweden
View GitHub Profile
@zemd
zemd / DeferredEvent.php
Created April 22, 2015 12:51
Deferred events via rabbitmq
<?php
/**
* Event that handles asynchronously via rabbitmq queue
*
* Usage:
* <code>
* $event = new DeferredEvent(new EmailEvent("[email protected]", "[email protected]", "message"));
* $dispatcher->dispatch("email.event", $event);
@zemd
zemd / AddCommandHandlersPass.php
Created April 22, 2015 12:30
API DDD prototype
<?php
class AddCommandHandlersPass implements CompilerPassInterface
{
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param ContainerBuilder $container
@zemd
zemd / ParseGeonamesCommand.php
Created April 8, 2015 19:51
Parsing data from geonames.org to mongodb
<?php
namespace Opesho\CommonBundle\Command;
use MongoClient;
use MongoDate;
use MongoDB;
use SplStack;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
@zemd
zemd / DateType.php
Last active August 29, 2015 14:18
Fixing storing dates' milliseconds in mongodb with DoctrineODM
<?php
namespace Opesho\CommonBundle\Doctrine\ODM\MongoDB\Types;
use Doctrine\ODM\MongoDB\Types\Type;
use Opesho\CommonBundle\Utils\DateUtils;
class DateType extends Type
{
public function convertToDatabaseValue($value)
@zemd
zemd / gist:0c0dfb5a5733a6ba279b
Created February 19, 2015 15:20
working with \DateTime
<?php
date_default_timezone_set('UTC');
$micro = explode(" ", microtime());
$micros = substr($micro[0], 1, 7);
$date = date('Y-m-d H:m:i');
$dtString = $date . $micros;
$datetime = DateTime::createFromFormat('Y-m-d H:m:i.u', $dtString, new DateTimeZone('UTC'));
$datetime2 = new DateTime($dtString, new DateTimeZone('UTC'));
$datetime3 = new DateTime("now", new DateTimeZone('UTC'));
@zemd
zemd / gist:8322a670f3c2a8da0ec6
Created July 12, 2014 21:54
string patching to make slug from current value
require 'iconv'
require 'active_support/core_ext/string'
String.class_eval do
def slugify
Iconv.conv('ASCII//TRANSLIT//IGNORE', 'UTF8', self.mb_chars.downcase).parameterize
end
end
@zemd
zemd / gist:4eb1969f1de30a4d098f
Created June 22, 2014 14:39
recursive rmdir
<?php
$dirPath = __DIR__.'/../app/cache/dev';
if (file_exists($dirPath)) {
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirPath, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path) {
$path->isDir() ? rmdir($path->getPathname()) : unlink($path->getPathname());
}
rmdir($dirPath);
}
@zemd
zemd / gist:8819458
Created February 5, 2014 08:41
remove files from git after .gitignore updated
git rm --cached `git ls-files -i --exclude-from=.gitignore`
@zemd
zemd / README.md
Created January 30, 2014 22:14 — forked from fnichol/README.md

Why?

There is a long standing issue in Ruby where the net/http library by default does not check the validity of an SSL certificate during a TLS handshake. Rather than deal with the underlying problem (a missing certificate authority, a self-signed certificate, etc.) one tends to see bad hacks everywhere. This can lead to problems down the road.

From what I can see the OpenSSL library that Rails Installer delivers has no certificate authorities defined. So, let's go fetch some from the curl website. And since this is for ruby, why don't we download and install the file with a ruby script?

Installation

The Ruby Way! (Fun)

@zemd
zemd / gist:8547144
Created January 21, 2014 19:55
hstore extension with rails migrations
class SetupHstore < ActiveRecord::Migration
def self.up
enable_extension "hstore"
end
def self.down
disable_extension "hstore"
end
end