Skip to content

Instantly share code, notes, and snippets.

View jmikola's full-sized avatar
💭
🌭

Jeremy Mikola jmikola

💭
🌭
View GitHub Profile
@jmikola
jmikola / irc.log
Created February 20, 2015 16:32
Who is jortSort?
[11:25] <jmikola> can you explain http://jort.technology/ to me?
[11:25] <jmikola> i read the page very carefully but i still couldn't figure out what it does
[11:25] <jmikola> again, barely in the tech field at this point
[11:26] <jmikola> i assume it makes the user sort things via some prompts?
[11:26] <jmikola> in which case it's super slow
[11:27] <dcousineau> jmikola: there is nothing to understand
[11:27] <jmikola> oh wait
[11:27] <jmikola> i just ran it in the mongo shell
[11:27] <jmikola> wtf
[11:27] <jmikola> this is pointless
@jmikola
jmikola / PedantryTest.php
Created March 18, 2015 21:47
Pedantic tests that have nothing to do with functional correctness
<?php
namespace MongoDB\Tests;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ReflectionClass;
use ReflectionMethod;
use RegexIterator;
@jmikola
jmikola / transcript.txt
Last active August 29, 2015 14:19
Lone Star PHP ReactPHP chat server
Script started on Sat 18 Apr 2015 01:41:51 PM CDT
$ telnet jmikola.net 8888
Trying 97.107.131.54...
Connected to jmikola.net.
Escape character is '^]'.
Hello.
24.173.35.158: Hi!
24.173.35.158: GET / HTTP/1.1
Host: jmikola.net:8888
Connection: keep-alive
@jmikola
jmikola / bench.log
Created May 25, 2015 14:57
Benchmarking PHP exception throws and backtrace generation
$ php bench.php
Throwing: 0.060640
Assigning and throwing: 0.064791
Assigning once and throwing: 0.011064
@jmikola
jmikola / README.md
Last active August 29, 2015 14:23
Testing memory usage with MongoGridFS::storeFile()

Configuration

For our tests, we used random input data created cat /dev/urandom > random.txt.

Set the URI, database, and GridFS collection names accordingly. Additionally, decide if the GridFS collection should be dropped before inserting any data.

The number of iterations can be customized. Based on the results, there were modest increases to peak memory on successive iterations. Real memory usage tended to drop with each new iteration and climb again.

By default, the driver uses a chunk size of 255 * 1024 (i.e. 255K). This default seems to leak memory (at least until the file insert completes). Increasing the chunk size even just a bit 256K has vastly better results.

@jmikola
jmikola / symfony2_forms_validation_groups.php
Created June 11, 2010 20:23
Using grouped constraints with Symfony 2 Forms
<?php
/* Since the group name is specified, "Default" will be assigned automatically and
* the implicity group name "Registration" (based on containing class' name) will
* also not be assigned.
*/
class Registration
{
public $field;
@jmikola
jmikola / DoctrineOdmUnique.php
Created June 14, 2010 22:28
DoctrineOdmUnique Constraint for Symfony 2 Forms
<?php
namespace Application\Validator\Constraints;
use Symfony\Components\Validator\Constraint;
class DoctrineOdmUnique extends Constraint
{
public $message = 'OpenSky.Validator.DoctrineOdmUnique.message';
public $documentManager;
@jmikola
jmikola / ProjectConfiguration.class.php
Created June 23, 2010 04:49
Symfony 1.4 ProjectConfiguration for ServerGrove with local vendor/symfony fallback
<?php
/**
* ServerGrove's shared Symfony libraries are not accessible within chrooted
* sessions on shared hosting, which means the symfony console command is
* unusable. The following conditional will allow you to fall back to a
* local copy of Symfony in your project's vendor directory and still make
* use of ServerGrove's up-to-date libraries elsewhere.
*
* Note: you likely won't have access to Doctrine or Propel commands, since
@jmikola
jmikola / fitzify.php
Created July 28, 2010 22:36
Add a random number of tabs to random lines in a string
<?php
function fitzify ($input) {
return implode(\PHP_EOL, array_map(function($line) {
return $line . (rand(1, 4) == 1 ? str_repeat("\t", rand(1, 4)) : '');
}, explode(\PHP_EOL, $input)));
}
$a = file_get_contents(__FILE__);
echo fitzify($a);
@jmikola
jmikola / mongo_normalize_address_countries.js
Created August 27, 2010 19:22
Normalize address countries to uppercase
var cols = ['customers', 'sellers', 'suppliers'];
for (j in cols) {
db[cols[j]].find({'addresses.country':/[a-z]/}).forEach(function(d){
for (i in d.addresses) {
d.addresses[i].country = d.addresses[i].country.toUpperCase();
}
db[cols[j]].save(d);
});
}