Skip to content

Instantly share code, notes, and snippets.

View eggie5's full-sized avatar
💭
Working on TensorFlow Ranking

Alex Egg eggie5

💭
Working on TensorFlow Ranking
View GitHub Profile
@mhfs
mhfs / imagemagick_rmagick.rb
Created February 3, 2010 17:57
Homebrew ImageMagick formula that plays nice with RMagick
require 'formula'
# some credit to http://github.com/maddox/magick-installer
# NOTE please be aware that the GraphicsMagick formula derives this formula
def ghostscript_srsly?
ARGV.include? '--with-ghostscript'
end
def x11?
@codeinthehole
codeinthehole / run.py
Created November 21, 2012 13:46
Sample Celery chain usage for processing pipeline
from celery import chain
from django.core.management.base import BaseCommand
from . import tasks
class Command(BaseCommand):
def handle(self, *args, **kwargs):
@sap1ens
sap1ens / backbone-custom-method.js
Created February 1, 2013 16:35
Adding Backbone.js custom REST method
var MyModel = Backbone.Model.extend({
someMethod: function(opts) {
var url = this.url() + '/someMethod',
// note that these are just $.ajax() options
options = {
url: url,
type: 'POST'
};
// add any additional options, e.g. a "success" callback or data
@wrburgess
wrburgess / gist:5528649
Last active November 24, 2022 15:29
Backup Heroku Postgres database and restore to local database

Grab new backup of database

Command: heroku pgbackups:capture --remote production

Response: >>> HEROKU_POSTGRESQL_COLOR_URL (DATABASE_URL) ----backup---> a712

Get url of backup download

Command: heroku pgbackups:url [db_key] --remote production

@epicserve
epicserve / redis_key_sizes.sh
Last active February 21, 2024 18:30
A simple script to print the size of all your Redis keys.
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
require 'fiddle'
module Python
def __class__= k
value = _wrap self
[k.object_id<<1].pack('Q').unpack('C8').each_with_index {|n,i|value[i+8]=n}
end
def _wrap klass; Fiddle::Pointer.new Fiddle.dlwrap klass; end
end
@mblondel
mblondel / letor_metrics.py
Last active April 24, 2024 19:43
Learning to rank metrics.
# (C) Mathieu Blondel, November 2013
# License: BSD 3 clause
import numpy as np
def ranking_precision_score(y_true, y_score, k=10):
"""Precision at rank k
Parameters
@astrojuanlu
astrojuanlu / reducebykey.py
Created December 28, 2015 19:04
Python implementation of Spark reduceByKey()
from functools import reduce
from itertools import groupby
def reduceByKey(func, iterable):
"""Reduce by key.
Equivalent to the Spark counterpart
Inspired by http://stackoverflow.com/q/33648581/554319
@charanpald
charanpald / recommendexp.py
Created January 26, 2016 13:34
Generate MovieLens recommendations using the SVD
# Run some recommendation experiments using MovieLens 100K
import pandas
import numpy
import scipy.sparse
import scipy.sparse.linalg
import matplotlib.pyplot as plt
from sklearn.metrics import mean_absolute_error
data_dir = "data/ml-100k/"
data_shape = (943, 1682)
@jgillman
jgillman / restore.sh
Last active March 8, 2024 17:51
pg_restore a local db dump into Docker
# Assumes the database container is named 'db'
DOCKER_DB_NAME="$(docker-compose ps -q db)"
DB_HOSTNAME=db
DB_USER=postgres
LOCAL_DUMP_PATH="path/to/local.dump"
docker-compose up -d db
docker exec -i "${DOCKER_DB_NAME}" pg_restore -C --clean --no-acl --no-owner -U "${DB_USER}" -d "${DB_HOSTNAME}" < "${LOCAL_DUMP_PATH}"
docker-compose stop db