Skip to content

Instantly share code, notes, and snippets.

@julesbou
julesbou / collection-of-objects.php
Created February 2, 2011 15:38
Symfony2 Mustache improvements
<?php
// Mustache only support single dimensional array
// With this patch, we can pass an array of objects to Mustache::renderString
$string = '{{var.foo}}';
$parameters = array('var' => new Object());
array
0 =>
array
empty
1 =>
array
empty
2 =>
array
empty
security:
access_control:
- { path: /admin/.*, role: ROLE_ADMIN }
- { path: /.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
encoders:
admin: { algorithm: sha1, class: Sas\CoreBundle\Entity\Account }
providers:
fos_user:
id: fos_user.user_manager
firewalls:
security:
acl: ~
access_control:
- { path: /admin/.*, role: ROLE_ADMIN, host: resowl2.com }
- { path: /.*, roles: [IS_AUTHENTICATED_ANONYMOUSLY, ROLE_USER] }
encoders:
admin: { algorithm: sha1, class: Sas\CoreBundle\Entity\Account }
providers:
fos_user:
id: fos_user.user_manager
[PHP]
;;;;;;;;;;;;;;;;;;;
; About php.ini ;
;;;;;;;;;;;;;;;;;;;
; PHP's initialization file, generally called php.ini, is responsible for
; configuring many of the aspects of PHP's behavior.
; PHP attempts to find and load this configuration from a number of locations.
; The following is a summary of its search order:
<?php
$lines = file('http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1');
$two = array();
$three = array();
$four = array();
$five = array();
foreach ($lines as $line) {
@julesbou
julesbou / gist:1158943
Created August 20, 2011 10:37
For the love of god don't do this!
<?php
foreach ($this->models as $model) {
$_file = '../' . $this->app . 'Models/' . $model . 'Model.php';
$_class = $model . 'Model';
if (file_exists($_file)) {
require_once $_file;
$this->{ucfirst($model)} = new $_class(null, dbConfig::$default);
} else {
@julesbou
julesbou / backend.php
Created September 11, 2011 21:48
Is it a good idea ? (not tested)
<?php
// Alternative to the long polling system used in lichess (github.com/ornicar/lichess)
// - We could use an ajax request on a php script with an infinite loop until version has changed.
$userVersion = $_GET['version']
$version = $db->stack->find($_GET['player_id'])->getVersion();
while ($userVersion <= $version) {
usleep(10000);
@julesbou
julesbou / benchmark.php
Created September 12, 2011 22:31
[benchmark] text file VS mysql VS apc
<?php
// Usage:
//
// $ php benchmar.php
// or
// $ php benchmark.php 1000 // to execute 1000 times
$pdo = new \PDO('sqlite://:memory:');
$pdo->exec("CREATE TABLE IF NOT EXISTS `Users` (
@julesbou
julesbou / socket-io-backbone-collection.js
Created March 25, 2012 12:04
Integrate SocketIO events into your Backbone.Collection
// Let you listen to SocketIO events into your Collection
var socket
Backbone.Collection.prototype.initialize = function() {
var events = this.socketEvents
for (var eventName in events) {