Skip to content

Instantly share code, notes, and snippets.

View josephmisiti's full-sized avatar

Joseph Misiti josephmisiti

View GitHub Profile
function grf(){
# restores file that was deleted. to run
# cd into the directory of the file and type
# grf filename-that-was-deleted
git checkout $(git rev-list -n 1 HEAD -- "$1")^ -- "$1"
}
@paulcnichols
paulcnichols / lda.py
Created September 24, 2012 17:58
LDA topic modeling using python's gensim.
from gensim import corpora, models, similarities, utils
import logging
import os
import re
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
class DirectoryCorpus(corpora.TextCorpus):
def get_texts(self):
@mbostock
mbostock / .block
Last active September 30, 2016 16:15
Reprojecting CSV with ogr2ogr
license: gpl-3.0
@dannguyen
dannguyen / Notes-on-stop-and-frisk-data.md
Last active November 22, 2016 06:55
A shell script to clean up the NYPD stop and frisk data (2003 to 2013) and upload it to BigQuery,
@vlado
vlado / gist:1877457
Last active April 3, 2018 08:36
Postgres on macos or OSX - Fix
# ** ERROR 1 **
# FATAL: lock file "postmaster.pid" already exists
# HINT: Is another postmaster (PID 4646) running in data directory "/usr/local/var/postgres"?
#
# ** ERROR 2 **
# Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
#
# To fix one of this errors:
cat /usr/local/var/postgres/postmaster.pid # pid is the number on first line
@blainerothrock
blainerothrock / gen.swift
Last active July 12, 2018 15:56
A Very Simple Genetic Algorithm Written in Swift 3
#!/usr/bin/env xcrun swift -O
/*
gen.swift is a direct port of cfdrake's helloevolve.py from Python 2.7 to Swift 3
-------------------- https://gist.github.com/cfdrake/973505 ---------------------
gen.swift implements a genetic algorithm that starts with a base
population of randomly generated strings, iterates over a certain number of
generations while implementing 'natural selection', and prints out the most fit
string.
The parameters of the simulation can be changed by modifying one of the many
@robintema
robintema / GeneralSerializer.py
Last active December 7, 2020 14:10
General Django Rest Framework model serializer
import logging
from rest_framework import serializers
class GeneralModelSerializer(serializers.ModelSerializer):
""" General model serializer that will serialize a model object. It will return all the model fields.
"""
class Meta:
model = None

Creating a redis Module in 15 lines of code!

A quick guide to write a very very simple "ECHO" style module to redis and load it. It's not really useful of course, but the idea is to illustrate how little boilerplate it takes.

Step 1: open your favorite editor and write/paste the following code in a file called module.c

#include "redismodule.h"
/* ECHO <string> - Echo back a string sent from the client */
int EchoCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
@surjikal
surjikal / nginx-s3.conf
Last active April 9, 2022 03:32
Nginx - Wildcard subdomains, basic auth and proxying to s3. Set a policy to only allow your server's IP.
server {
listen 80;
server_name *.foo.example.com;
# We need this to resolve the host, because it's a wildcard.
# This is google's DNS server.
resolver 8.8.8.8;
include /etc/nginx/includes/proxy.conf;
@zacstewart
zacstewart / classifier.py
Last active March 27, 2023 15:59
Document Classification with scikit-learn
import os
import numpy
from pandas import DataFrame
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import Pipeline
from sklearn.cross_validation import KFold
from sklearn.metrics import confusion_matrix, f1_score
NEWLINE = '\n'