Skip to content

Instantly share code, notes, and snippets.

@mulderp
mulderp / gist:7089766
Created October 21, 2013 19:48
redis movies import
var url = require('url');
var _ = require('underscore');
var querystring = require('querystring');
var Promise = require("bluebird");
//assume client is a redisClient
//
var now = (typeof Date.now === 'function')? Date.now : function(){
return +(new Date());
@mulderp
mulderp / gist:7089617
Created October 21, 2013 19:37
movies data
[
{
"id": 12,
"genres": [
"Drama",
"Comedy"
],
"rating": 0,
"description": "A silent movie star meets a young dancer, but the arrival of talking pictures sends their careers in opposite directions.",
"title": "The Artist",
@mulderp
mulderp / gist:7045228
Created October 18, 2013 17:45
nested promises
function allMovies() {
return client.smembersAsync('movies.ids').then(function(ids) {
var movies = _.map(ids, function(id) {
return client.hmgetAsync("movies:" + id, 'title', 'description', 'director', 'year').then(function(data) {
return {
title: data[0],
description: data[1],
director: data[2],
year: data[3]
};
@mulderp
mulderp / createUser
Created October 11, 2013 20:41
User signup with Node and Redis
function createUser(raw, success_cb, fail_cb) {
var userId;
console.log("enter");
async.waterfall([
function(cb) {
// Increase
client.hincrby('users', 'count', 1, cb);
@mulderp
mulderp / gist:6628444
Created September 19, 2013 19:14
Stretcher test new SearchResults
server = Stretcher::Server.new('http://localhost:9200', :log_level => :debug)
server.index(:moviesdb1).create(mappings: {movie: {properties: {title: {type: 'string'}, genres: {type: 'string', index_name: 'genre1'}}}})
# [Stretcher][DEBUG]: curl -XPUT http://localhost:9200/moviesdb1 -d '{"mappings":{"movie":{"properties":{"title":{"type":"string"},"genres":{"type":"string","index_name":"genre1"}}}}}' '-H Accept: application/json' '-H Content-Type: application/json' '-H User-Agent: Stretcher Ruby Gem 1.20.0.beta1'
# => #<Hashie::Mash acknowledged=true ok=true>
server.index(:moviesdb1).type(:movie).put(1, { title: 'The Artist', genres: ['Drama', 'Comedy']})
server.index(:moviesdb1).type(:movie).put(2, { title: 'Taxi Driver', genres: ['Drama', 'Action']})
# Index
---------------------------------------------------------------------
curl -XPUT http://localhost:9200/pictures/ -d '
{
"settings": {
"analysis": {
"analyzer": {
"index_analyzer": {
"tokenizer": "standard",
@mulderp
mulderp / gist:5135267
Created March 11, 2013 15:58
cookbook rvm
class Chef::Resource::Script
def log_code command
if Chef::Config[:log_level] == :debug
code "{ #{command}; _ret=$?; echo \"Exit status was $_ret.\"; exit $_ret; } 2>&1 |
tee /var/log/#{@command.to_s.gsub(/ /,"_")}.log; exit ${PIPESTATUS[0]}"
else
code command
end
end
end
-rw-r--r-- 1 root root 2067 Mar 11 11:37 install_rvm.log
-rw-r--r-- 1 root root 1349 Mar 11 11:37 install_rvm_requirements.log
-rw-r--r-- 1 root root 302 Mar 11 11:37 uninstall_ruby-1.9.3-p374.log
-rw-r--r-- 1 root root 3742 Mar 11 11:39 install_ruby-1.9.3-p374.log
-rw-r--r-- 1 root root 850 Mar 11 11:39 package_ruby-1.9.3-p374.log
-rw-r--r-- 1 root root 300 Mar 11 11:39 uninstall_ruby-2.0.0-rc1.log
-rw-r--r-- 1 root root 3779 Mar 11 11:43 install_ruby-2.0.0-rc1.log
-rw-r--r-- 1 root root 845 Mar 11 11:43 package_ruby-2.0.0-rc1.log
@mulderp
mulderp / gist:5125458
Last active December 14, 2015 17:58
centering some divs
.content {
width: 600px;
margin: 0 auto 0;
margin-bottom: 0;
}
.sidebar {
position: fixed;
left: 15px;
@mulderp
mulderp / gist:3794314
Created September 27, 2012 14:31
API spec
require 'spec_helper'
require 'vcr'
require 'fakeweb'
require 'pry'
VCR.configure do |c|
c.cassette_library_dir = 'fixtures/vcr_cassettes'
c.hook_into :fakeweb
end