Skip to content

Instantly share code, notes, and snippets.

View n1k0's full-sized avatar
✏️
writing a github status

Nicolas Perriault n1k0

✏️
writing a github status
View GitHub Profile

Hey, Django rookie here.

I have this model, comments are managed with the django_comments contrib:

class Fortune(models.Model):
    author = models.CharField(max_length=45, blank=False)
    title = models.CharField(max_length=200, blank=False)
    slug = models.SlugField(_('slug'), db_index=True, max_length=255, unique_for_date='pub_date')
    content = models.TextField(blank=False)

pub_date = models.DateTimeField(_('published date'), db_index=True, default=datetime.now())

@n1k0
n1k0 / twittersearch.json.php
Created May 15, 2010 19:58
retrieves latest 100 tweets for a given search in the twitter timeline
<?php
$searchtag = '#plop';
$tweets = json_decode(file_get_contents('http://search.twitter.com/search.json?rpp=100&q='.urlencode($searchtag)));
foreach ($tweets->results as $tweet) {
echo sprintf("@%s: %s\n", $tweet->from_user, (string) $tweet->text);
}
## This script will map a standard CSV file to a python list containing a dict for each row
import csv
reader = csv.reader(open('foobar.csv'), delimiter=',', quotechar='"')
fields = reader.next() # field names are in the first line
results = []
<?php
/**
* This Doctrine Cache Apc class adds a 'prefix' option in order to handle
* different APC environments or setups for storing query and cache results
*
* @author Nicolas Perriault
* @license WTFPL
*/
class Doctrine_Cache_Namespaced_Apc extends Doctrine_Cache_Apc
{
@n1k0
n1k0 / plop.php
Created September 21, 2010 08:00
<?php
// example of a locally computed virtual property
class Book extends Doctrine_Record
{
public function getSynopsys($length = 200)
{
return substr($this->abstract.$this->cover, 0, $length);
}
public function setSynopsys($value)
Transactions: 216 hits
Availability: 99.54 %
Elapsed time: 59.63 secs
Data transferred: 0.71 MB
Response time: 3.54 secs
Transaction rate: 3.62 trans/sec
Throughput: 0.01 MB/sec
Concurrency: 12.84
Successful transactions: 216
Failed transactions: 1
# -*- coding: utf-8 -*-
import memcache
import random
NS_KEY_RANGE_MAX = 1000000
mc = memcache.Client(['127.0.0.1:11211'], debug=0)
@n1k0
n1k0 / test.js
Created September 10, 2011 15:28
PhantomJS, arraybuffer and obsolete webkit version :(
var page = new WebPage();
page.open('http://www.google.fr/', function(status) {
var base64 = page.evaluate(function() {
function base64ArrayBuffer(arrayBuffer) {
var base64 = ''
var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
var bytes = new Uint8Array(arrayBuffer)
var byteLength = bytes.byteLength
var byteRemainder = byteLength % 3
var mainLength = byteLength - byteRemainder
@n1k0
n1k0 / betterTypeOf.js
Created November 2, 2011 08:57
A better typeof for JavaScript, with tests cases
/**
* @see http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
*/
function betterTypeOf(input) {
try {
return Object.prototype.toString.call(input).match(/^\[object\s(.*)\]$/)[1].toLowerCase();
} catch (e) {
return typeof input;
}
}
@n1k0
n1k0 / Action.class.php
Created November 3, 2011 15:26 — forked from clemherreman/Action.class.php
Class action
<?php
class Action
{
public function goFuckYourself() {
return andCry();
}
}