Skip to content

Instantly share code, notes, and snippets.

import re
# http://atomboy.isa-geek.com/plone/Members/acoil/programing/double-metaphone
from metaphone import dm as double_metaphone
# get the Redis connection
from jellybean.core import redis
import models
# Words which should not be indexed
@lancejpollard
lancejpollard / awesome_nested_set_optimization_helper.rb
Created July 2, 2010 01:39
Goal: Convert entire hierarchy of models into tree in 1 database call, such that you can loop through them depth-first
def simple_nested_set(clazz) # Post for example
stack = [] # Post for example
result = []
clazz.all(:order => "lft").each do |node|
if stack.empty?
stack.push({:node => node, :children => []})
result << stack.last
next
end
if stack.last[:node].lft < node.lft && node.lft < stack.last[:node].rgt
@MichelBartz
MichelBartz / Comments.php
Created January 30, 2011 21:07
Nested Comments using Redis. Rely on the Owlient Redis extension
<?php
/**
* A Nested Comments manager using Redis only
* @author Michel Bartz <michel.bartz@manwin.com>
* @date 01/28/2011
*/
class Comments
{
private $_redis;
@necolas
necolas / snippet.js
Created June 14, 2011 20:36
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@gingerlime
gingerlime / redis-request-irregularities-ruby.md
Created November 1, 2012 11:40
Redis Request iRregularities with Ruby

... I couldn't resist the temptation for some pseudo-alliteration.

Need for speed

When it comes to driving, I'm a rather slow driver. I can parallel park with my eyes-closed, merge in traffic easily, but I really don't enjoy driving fast (Mind you, I take public transport these days). But when it comes to squeezing performance out of a system, I guess I'm much more attracted to the idea of things running fast. The redis attraction is therefore quite obvious. In-memory database. It doesn't get much faster than that.

Bumps on the road

It was rather surprising to come across speed issues with redis, and fairly early-on with our project. At kenHub, we are building an anatomy learning platform. The platform must adapt to each and every student, and present them with the best question for their level. To do this, we must store statistics for each and every anatomy term for each user. Redis was a natural candidate for this. Quick access to read/write individual records allows us to u

@KartikTalwar
KartikTalwar / Documentation.md
Last active June 13, 2024 07:02
Rsync over SSH - (40MB/s over 1GB NICs)

The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

This creates an archive that does the following:

rsync (Everyone seems to like -z, but it is much slower for me)

  • a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
  • H: preserves hard-links
  • A: preserves ACLs
<?php
with(new Page())->makeRoot();
with(new Page())->makePreviousSiblingOf(Page::find(1))
with(new Page())->makeNextSiblingOf(Page::find(1))
with(new Page())->makeLastChildOf(Page::find(5))
with(new Page())->makeFirstChildOf(Page::find(2))
Page::find(2)->children()
Page::find(2)->parent()
Page::find(2)->sibling()
Page::find(2)->isDescendant(Page::find(3))
@willurd
willurd / web-servers.md
Last active June 21, 2024 13:36
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@adamcbrewer
adamcbrewer / css-sass-helpers.scss
Last active August 23, 2023 23:04
SASS: Helpers and mixins for using with SASS
//============================================================
// Typography
//============================================================
// An rem font-size mixin providing fallback to px
@mixin font-size($sizeValue: 1.4) {
$remValue: $sizeValue;
$pxValue: ($sizeValue * 10);
font-size: #{$pxValue}px;
font-size: #{$remValue}rem;
@iJackUA
iJackUA / install-redis-ubuntu.sh
Last active July 25, 2017 06:09
Install Redis from source (Ubuntu)
#!/bin/bash
if [ "$(whoami)" != "root" ]; then
echo "ERROR : Run script as Root (sudo !!) please"
exit 1
fi
read -e -p "Redis version to be installed (change if needed) : " -i "2.8.2" VERSION
echo 'Installing redis v.'$VERSION' ... '