Skip to content

Instantly share code, notes, and snippets.

View jfcalvo's full-sized avatar

José Francisco Calvo jfcalvo

View GitHub Profile
@miguelgarcia
miguelgarcia / factories.py
Last active January 29, 2024 13:08
Python: factoryboy + sqlalchemy. SubFactory and RelatedFactory example
# factories
class CategoryFactory(factory.alchemy.SQLAlchemyModelFactory):
class Meta:
model = models.Category
sqlalchemy_session = db.session
sqlalchemy_session_persistence = 'commit'
name = factory.Sequence(lambda n: u'Category %d' % n)
class CompanyFactory(factory.alchemy.SQLAlchemyModelFactory):
@Twinklebear
Twinklebear / main.cpp
Last active February 18, 2024 02:28
Example of render to texture with SDL2
#include <iostream>
#ifdef __linux__
#include <SDL2/SDL.h>
#elif defined(_WIN32)
#include <SDL.h>
#endif
const int WIN_WIDTH = 640;
const int WIN_HEIGHT = 480;
@dszeto
dszeto / import_ml10m.rb
Created July 28, 2013 05:01
Import MovieLens 10M data set from http://www.grouplens.org/node/73 to PredictionIO 0.5.0
require "predictionio"
if (ARGV[0].nil? || ARGV[1].nil?)
abort("Usage: import_ml.rb <app key> <movie lens data file>")
end
client = PredictionIO::Client.new(ARGV[0],
50,
"http://localhost:5586")
@trey
trey / happy_git_on_osx.md
Last active February 18, 2024 10:46
Creating a Happy Git Environment on OS X

Creating a Happy Git Environment on OS X

Step 1: Install Git

brew install git bash-completion

Configure things:

git config --global user.name "Your Name"

git config --global user.email "you@example.com"

@benedikt
benedikt / active_model_serializers.rb
Created March 2, 2012 17:40
Makes mongoid and active_model_serializers play nicely together
# config/initializers/active_model_serializers.rb
Mongoid::Document.send(:include, ActiveModel::SerializerSupport)
Mongoid::Criteria.delegate(:active_model_serializer, :to => :to_a)
@jimbojsb
jimbojsb / gist:1630790
Created January 18, 2012 03:52
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@wtaysom
wtaysom / where_is.rb
Created September 23, 2011 08:57
A little Ruby module for finding the source location where class and methods are defined.
module Where
class <<self
attr_accessor :editor
def is_proc(proc)
source_location(proc)
end
def is_method(klass, method_name)
source_location(klass.method(method_name))
@p01
p01 / LICENSE.txt
Last active March 9, 2024 13:40 — forked from 140bytes/LICENSE.txt
Sudoku Solver in 140bytes
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Mathieu 'p01' Henri - http://www.p01.org/releases/
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@oisin
oisin / gist:952572
Created May 2, 2011 23:36
API version checking using Sinatra's before filter
require 'sinatra'
# Set the version of the API being run here
#
MAJOR_VERSION = 1
MINOR_VERSION = 0
helpers do
def version_compatible?(nums)
return MAJOR_VERSION == nums[0].to_i && MINOR_VERSION >= nums[1].to_i
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby