Skip to content

Instantly share code, notes, and snippets.

View chrisguitarguy's full-sized avatar

Christopher Davis chrisguitarguy

View GitHub Profile
@chrisguitarguy
chrisguitarguy / example.sh
Created February 14, 2016 17:06
Update calls to `createForm` in Symfony controllers to use class names instead of instances
find path/to/Bundle/Controller -type f -name '*.php' -exec sed -i '' 's/createForm(new \(.*\)()/createForm(\1::class/' {} \;
@chrisguitarguy
chrisguitarguy / ajax.js
Last active November 27, 2015 02:37
Turns out it's pretty simple to write a little promised-based ajax wrapper
var assign = require('object-assign');
var Promise = require('es6-promise').Promise;
var EventEmitter = require('eventemitter2').EventEmitter2;
function buildQueryString(object, prefix) {
var out = [];
for (var prop in object) {
if (!object.hasOwnProperty(prop)) {
continue;
}
#!/usr/bin/env boot
(require '[clojure.string :as string])
(defn- str->int [s]
(Integer/parseInt s))
(defn- positive? [n]
(> n 0))
(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+")))})