Skip to content

Instantly share code, notes, and snippets.

View michaeltwofish's full-sized avatar

Michael C. Harris michaeltwofish

  • South Australia, Australia
View GitHub Profile
@michaeltwofish
michaeltwofish / gist:2410753
Created April 18, 2012 02:48
Lithium MongoDB unique tags from users
Get
array
'assertion' => string 'reduce -> multiple not supported yet' (length=36)
'assertionCode' => int 10075
'errmsg' => string 'db assertion failure' (length=20)
'ok' => float 0
From
@michaeltwofish
michaeltwofish / gist:2515912
Created April 28, 2012 04:30
Left join query
SELECT *, count(client_tests.id) AS test_count FROM clients LEFT JOIN client_tests ON clients.id = client_tests.client_id GROUP BY clients.id;
# cat /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux (EPEL)
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
// Set the default connection based on the environment
Connections::add('default', array(
'development' => array(
'type' => 'MongoDb',
'host' => '127.0.0.1',
'database' => 'schools',
),
'test' => array(
'type' => 'MongoDb',
'host' => '10.10.20.4',
var req = https.request( options, function( res ) {
var data = '';
res.on('data', function( chunk ) {
data += chunk;
});
@michaeltwofish
michaeltwofish / mongoid.yml
Created June 6, 2012 05:42
mongoid configuration
development:
sessions:
default:
database: delivery_test
hosts:
- 127.0.0.1:27017
def fizzbuzz(number)
case
when number % 3 == 0 && number % 5 == 0
"Fizz, Buzz"
when number % 3 == 0
"Fizz"
when number % 5 == 0
"Buzz"
else
number.to_s
@michaeltwofish
michaeltwofish / gist:3958689
Created October 26, 2012 13:07
Slow query, extra field that the whole collection shares same value
> db.sittings.find({ "user.id" : "504fffe45c69233171000000", "status_id" : { "$in" : [ 1, 2 ] }, "app" : "schools", "metadata.client_id" : "4" }).explain()
{
"cursor" : "BtreeCursor user.id_1",
"nscanned" : 4,
"nscannedObjects" : 4,
"n" : 4,
"millis" : 686,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
@michaeltwofish
michaeltwofish / gist:4113926
Created November 19, 2012 21:11
Last php error
lasterror () {
logpath=/usr/local/www-conf/logs/$1-phplog
error=(${(f)$(awk -F: '/PHP Fatal error|\[error\]/ { lines[last] = NR } END { print lines[last] }' $logpath)})
[[ -n $error ]] && tail -n +$error $logpath
}

Problem 1:

There is a big with the haabri markup plugin. Header links are not converted from markdown. Please see how this text looks in Byword or nvALT (if you use a Mac). Please update the plugin.

  • [What is The Key Method?][What is The Key Method?]

##What is The Key Method?

I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][].