Skip to content

Instantly share code, notes, and snippets.

View SupermanScott's full-sized avatar

Scott Reynolds SupermanScott

View GitHub Profile
@SupermanScott
SupermanScott / personal.el
Created January 11, 2014 17:58
personal.el
;;; personal.el -- personal modifications
;;; Commentary:
;;; provide personal modifications
;;; Code:
(set-face-attribute 'default nil :height 140)
(prelude-require-packages '(color-theme-sanityinc-tomorrow paredit ac-geiser
geiser))
(provide 'personal)
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
# config.vm.define :web do |web_config|
# web_config.vm.box = 'telly-base'
# web_config.vm.provision :shell, :path => "provisioners/web.sh"
# web_config.vm.forward_port 80, 6060
# web_config.vm.network :hostonly, "254.168.1.10"
# end
@SupermanScott
SupermanScott / gist:2821475
Created May 28, 2012 22:30
User 2's Feed
redis 127.0.0.1:6379[2]> zrevrange activity_feed:1:2 0 10
1) "activity_aggr:1:like:1:15488.0"
2) "activity_aggr:1:picture:1:15488.0"
@SupermanScott
SupermanScott / gist:2821467
Last active October 5, 2015 14:28
Follow user
>>> tasks.follow_user.delay(1, 2)
<AsyncResult: c570c9c3-13d8-4688-ae41-0ebbdc337f45>
@SupermanScott
SupermanScott / gist:2821453
Created May 28, 2012 22:22
redis_output_start
redis 127.0.0.1:6379[2]> keys *
1) "activity_aggr:1:picture:1:15488.0" # Aggregation for picture, user 1 and day 15488
2) "activity:1:1338243610.94:like" # Individual activity
3) "activity:1:1338243622.3:picture" # Individual activity
4) "activity_aggr:1:like:1:15488.0:counter" # counter for like, user 1 and day 15488
5) "activities:1" # All activities that user 1 has ever done.
6) "activity_profile:1:1" # Profile feed for user 1
7) "activity:1:1338243599.68:picture" # Individual activity
8) "activity_aggr:1:like:1:15488.0" # Aggregation for like, user 1 and day 15488
9) "activity_aggr:1:picture:1:15488.0:counter" # Counter for picture, user 1 and day 15488
@SupermanScott
SupermanScott / gist:2821439
Last active October 5, 2015 14:28
start.py
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> import tasks
>>> tasks.new_activity.delay(1, time.time(), 'picture')
<AsyncResult: 1cffc586-0442-4824-8c8f-7fc2c72de1ff>
>>> tasks.new_activity.delay(1, time.time(), 'like')
<AsyncResult: 20683c9f-676d-4f52-a911-b561f651bb0b>
>>> tasks.new_activity.delay(1, time.time(), 'picture')
@SupermanScott
SupermanScott / document.py
Created May 14, 2012 01:58
My attempt to do idempotent Mongo writes with MongoKit
# -*- coding: utf-8 -*-
# Copyright (c) 2012, Scott Reynolds
# All rights reserved.
from mongokit import Document, UpdateQueryError
from pymongo.errors import OperationFailure
from bson import BSON
import hashlib
class IdempotentDocument(Document):
<?php
public function createQueryDSL($query, $skip, $limit) {
$query_json = array(
'query' => array(
'custom_filters_score' => array(
'query' => array(
'query_string' => array(
'fields' => array('title^5', 'message', 'vanity_url^3', 'full_name^5'),
'query' => $query,
total = self.document_storage.count()
scope = dict(total=total)
results = self.collection.map_reduce(
map_function,
reduce_function,
finalize=finalize_function,
scope=scope,
query={'term': { '$in': list(terms)}},
finalize_function = bson.Code(
"function (key, value) {"
" var score = value.tf * Math.log(total / value.df);"
" return score;"
"}")