Skip to content

Instantly share code, notes, and snippets.

View mogetutu's full-sized avatar

Isaak Mogetutu mogetutu

View GitHub Profile
<?php
/**
* cURL Object Oriented API
* @author Stefano Azzolini <[email protected]>
*/
class cURL {
/**
* The cURL resource descriptor
* @var Resource

Never Expose DB Results Directly

  1. If you rename a field, then your users are fucked. Convert with a hardcoded array structure.
  2. Most DB drivers [for PHP] will show integers as numeric strings and false as "0", so you want to typecast them.
  3. Unless you're using an ORM with "hidden" functionality, people will see passwords, salts and all sorts of fancy codes. If you add one and forget to put it in your hidden array then OOPS!

Use the URI sparingly, and correctly

  1. Use the query string for paired params instead of /users/id/5/active/true. Your API does not need to be SEO optimised.
  2. ?format=xml is stupid, use an Accept: application/xml header.
<?php
print_r(new DateTime('01/01/2012'));
/*
Good
DateTime Object
(
[date] => 2012-01-01 00:00:00
[timezone_type] => 3
[timezone] => America/Chicago

Awesome PHP

A list of amazingly awesome PHP libraries, resources and shiny things.

Composer

App.AccountEditRoute = Ember.Route.extend({
setupController: function(controller) {
controller.set('content', this.get('currentUser'));
}
});
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with the same name as the keys in <tt>filtering_params</tt>
# with their associated values. Most useful for calling named scopes from

Creating your own Custom Live 11.04 CD.

1. Preparations

First you download the Live CD ISO. While it is downloading install some software that is needed for rebuilding: sudo apt-get install squashfs-tools dchroot

  • Squashfs Install squashfs-tools is a compressed read-only filesystem for Linux.
  • dchroot Install dchroot allows users to execute commands or interactive shells in different chroots.

Mount the Live CD:

require 'benchmark'
class SlowTrie
attr_accessor :word, :nodes
def initialize
@word, @nodes = false, {}
end
def <<(word)