Skip to content

Instantly share code, notes, and snippets.

View chrisguitarguy's full-sized avatar

Christopher Davis chrisguitarguy

View GitHub Profile
(require '[clojure.string :as string])
(defn- str->int [s]
(Integer/parseInt s))
(defn- parse-time [timestr]
(let [[hours mins secs-and-ampm] (string/split timestr #":" 3)
secs (subs secs-and-ampm 0 2)
ampm (subs secs-and-ampm 2)]
{:hours (str->int hours)
#!/usr/bin/env boot
(require '[clojure.string :as string])
(defn- str->int [s]
(Integer/parseInt s))
(defn- parse-row [row expected-count]
{:post [(= expected-count (count %))]}
(map str->int (string/split row #"\s+")))
<?php
interface SomeObjectRepository
{
public function getByIdentifier($id);
public function findAll();
public function add(SomeObject $object);
<?php
interface Article
{
public function getIdentifier();
public function getTitle();
public function setTitle($title);
public function getBody();
public function setBody($body);
public function getYear();
@chrisguitarguy
chrisguitarguy / mongo.php
Last active August 29, 2015 14:28
Just some MongoDB PHP API Weirdness I guess?
<?php
$mongo = new \MongoClient();
$col = $mongo->testDb->testCollection;
$col->drop();
$col->insert(['test' => 'one']);
// works perfectly
var_dump(iterator_to_array($col->find([
'test' => 'one',
], ['test'])));
@chrisguitarguy
chrisguitarguy / mongowtf.php
Last active August 29, 2015 14:28
Does $setOnInsert not work with a projection?
<?php
$mongo = new \MongoClient();
$col = $mongo->testDb->testCollection;
$col->drop();
// only returns the `_id` attribute, despite the "fields" argument
var_dump($col->findAndModify([
'test' => 'one',
#!/usr/bin/env boot
(require '[clojure.string :as string])
(defn- string->int [string]
(Integer/parseInt string))
(defn- make-case [[credit num-items items]]
{:credit (string->int credit)
:items (map-indexed vector (map string->int (string/split items #"\s+")))})
@chrisguitarguy
chrisguitarguy / countries.php
Created August 18, 2015 21:12
A PHP array of ISO country codes to names
<?php
return array(
'AD' => 'Andorra',
'AE' => 'United Arab Emirates',
'AF' => 'Afghanistan',
'AG' => 'Antigua and Barbuda',
'AI' => 'Anguilla',
'AL' => 'Albania',
'AM' => 'Armenia',
'AO' => 'Angola',
@chrisguitarguy
chrisguitarguy / EnableSavepointsListener.php
Created August 12, 2015 21:56
Doctrine savepoints in Symfony
<?php
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Event\ConnectionEventArgs;
final class EnableSavepointsListener implements EventSubscriber
{
/**
* {@inheritdoc}
@chrisguitarguy
chrisguitarguy / notokay.php
Last active August 29, 2015 14:26
Weird PHP-ism. `notokay.php` produces an error. `ok.php` is just fine.
<?php
interface Ham
{
public function halp(\stdClass $obj=null);
}
class Spam implements Ham
{
public function halp(\stdClass $obj)