Skip to content

Instantly share code, notes, and snippets.

View PatrickLef's full-sized avatar

Patrick Lef PatrickLef

  • Looking for exciting projects!
  • Stockholm, Sweden
View GitHub Profile
/**
* This is a simple template for bug reproductions. It contains three models `Person`, `Animal` and `Movie`.
* They create a simple IMDB-style database. Try to add minimal modifications to this file to reproduce
* your bug.
*
* install:
* npm install objection knex sqlite3 chai
*
* run:
* node reproduction-template
@PatrickLef
PatrickLef / gist:4044822
Created November 9, 2012 09:36
Redis comment store ideas
I'm trying to figure out how to fetch comments for objects and optimize memory usage and lookup speed. One video has multiple comments and comments will always be fetched using VideoID or VideoID + CommentID.
Our setup: One master in Amazon and a slave on each Web server. The web-servers will deliver this data, so the web servers will fetch this locally.
Some stats: Every video has in general 10-20 comments.
Idea 1: Store comments in a hash with VideoID as key, Comment ID as field and comment-data as value. Then fetching the whole hash and sorting it based on a Sorted set with VideoID as key and CommentIDs as values.
Pros: Only two lookups to fetch all comments (One for Sorted list and One for the hash).
Cons: VideoID will always be needed to fetch a comment (Okay in our application). We are not utilizing the memory savings of using a hash too keep down the memory size used by redis.
Redis storage:
//
// showdown.js -- A javascript port of Markdown.
//
// Copyright (c) 2007 John Fraser.
//
// Original Markdown Copyright (c) 2004-2005 John Gruber
// <http://daringfireball.net/projects/markdown/>
//
// The full source distribution is at:
//
Story line för reklam för FEMME NATURAL BOOST:
Klockan är runt 10 på kvällen. Gudrun Schyman kommer hem från en tuff dag på jobbet och är helt slut.
Man ser rynkorna i hennes ansikte från hennes tuffa arbetsdag samtidigt som hon trött öppnar dörren
till sitt gula nymålade radhus. Hon tar några tunga steg fram till kylen och öppnar en FEMME NATURAL
BOOST. Hon öppnar burken och tar sig en första sipp. Hennes ögon skiner upp och hon blir genast mycket
piggare och häller i sig resten av innehållet ur burken. Hon sliter åt sig två stycken till och häller
i sig den ena kvickt samtidigt som hon springer ut genom ytterdörren och hoppar ner för trappstegen
utanför.
===============================================
============== R E Q U E S T =====================
===============================================
POST /xmlrpc.php HTTP/1.1
Accept: */*
Connection: keep-alive
User-Agent: XMLRPC::Client (Ruby 1.8.7)
Content-Type: text/xml; charset=utf-8
Host: myshowroom.se
===============================================
============== R E Q U E S T =====================
===============================================
POST /xmlrpc.php HTTP/1.1
Accept: */*
Connection: keep-alive
User-Agent: XMLRPC::Client (Ruby 1.8.7)
Content-Type: text/xml; charset=utf-8
Host: myshowroom.se
@PatrickLef
PatrickLef / gist:957836
Created May 5, 2011 20:20
AR vs Yii AR
$post=new Post;
$post->title='sample post';
$post->content='post body content';
$post->save();
VS
Post.new(:title => 'sample post', :content => 'post body content').save
---
@PatrickLef
PatrickLef / Avoiding console.log crashes in IE
Created April 17, 2011 14:19
How to avoid console.* crashes in Internet Explorer
if (! ('console' in window) || !('firebug' in console)) {
var names = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'];
window.console = {};
for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
}
padrino generate project fisk
## app/models/blogger.rb
class Blogger < User
include BloggerUtils
end
## app/models/user.rb
class User
##
## SERVER (config.ru)
## Start with: thin start -V -R config.ru
app = proc do |env|
[
200,
{
'Content-Type' => 'text/html',
'Content-Length' => '2'