Skip to content

Instantly share code, notes, and snippets.

@jikamens
jikamens / encryption.py
Last active August 11, 2017 03:49
Python code for Schematics field encryption / decryption that is compatible with Ruby's mongoid-encrypted-fields + gibberish. The Encryptor object in this gist does encryption / decryption that is compatible with "openssl enc -k *password* -salt -aes-256-cbc". If you want it also to be compatible with mongoid-encrypted-fields, then you need to s…
import binascii
from Crypto.Cipher import AES
from Crypto.Random.random import getrandbits
from hashlib import md5
from schematics.types import StringType
import struct
class DecryptionException(Exception):
pass
@SEJeff
SEJeff / print_imports.py
Last active April 11, 2019 12:33
Print every python import for debugging import issues
# Courtesy of https://github.com/wimglenn
import sys
try:
import builtins
except ImportError:
# py2
import __builtin__ as builtins
@justinvw
justinvw / es_simple_autocomplete_example_config.sh
Last active January 26, 2021 17:15
Simple ElasticSearch autocomplete example configuration. The 'autocomplete' functionality is accomplished by lowercasing, character folding and n-gram tokenization of a specific indexed field (in this case "city").
# Delete the possibly existing autocomplete test index
curl -X DELETE localhost:9200/autocomplete_test
# Put the config of the autocomplete index
curl -X PUT localhost:9200/autocomplete_test -d '
{
"settings" : {
"index" : {
"analysis" : {
"analyzer" : {
@itamarhaber
itamarhaber / luainsider.md
Last active April 10, 2021 19:09
A micro OSS project, blog post or an addition to http://redis.io/topics|commands/eval|evalsha?

Luainsider - manage your Redis Lua scripts like a pro

A methodology, approach and apparatus for semi-persisting and aliasing Redis Lua scripts.

FAIR WARNING: this is WIP (i.e. could blow in your face)

Description

@larsmans
larsmans / heaps.erl
Created September 28, 2011 15:54
Priority queues (pairing heaps) in Erlang
% Copyright (c) 2010-2014, Lars Buitinck
% May be used, redistributed and modified under the terms of the
% GNU Lesser General Public License (LGPL), version 2.1 or later
% Heaps/priority queues in Erlang
% Heaps are data structures that return the entries inserted into them in
% sorted order. This makes them the data structure of choice for implementing
% priority queues, a central element of algorithms such as best-first/A*
% search and Kruskal's minimum-spanning-tree algorithm.
@jmatthias
jmatthias / uuid_column.py
Created February 27, 2014 23:48
Database-agnostic SQLAlchemy UUID column type
import psycopg2.extras
import sqlalchemy.dialects.postgresql
from sqlalchemy.types import TypeEngine
from sqlalchemy.types import String
from sqlalchemy.types import TypeDecorator
import uuid
# Required for PostgreSQL to accept UUID type.
psycopg2.extras.register_uuid()
@justanr
justanr / _core.py
Last active December 14, 2023 02:47
Clean Architecture In Python
from abc import ABC, ABCMeta, abstractmethod
from collections import namedtuple
from itertools import count
PayloadFactory = namedtuple('PayloadFactory', [
'good', 'created', 'queued', 'unchanged', 'requires_auth',
'permission_denied', 'not_found', 'invalid', 'error'
])
"""
@acolyer
acolyer / service-checklist.md
Last active January 30, 2024 17:39
Internet Scale Services Checklist

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?
@popravich
popravich / PostgreSQL_index_naming.rst
Last active March 25, 2024 12:42
PostgreSQL index naming convention to remember

The standard names for indexes in PostgreSQL are:

{tablename}_{columnname(s)}_{suffix}

where the suffix is one of the following:

  • pkey for a Primary Key constraint;
  • key for a Unique constraint;
  • excl for an Exclusion constraint;
  • idx for any other kind of index;
@KartikTalwar
KartikTalwar / Documentation.md
Last active April 13, 2024 23:09
Rsync over SSH - (40MB/s over 1GB NICs)

The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

This creates an archive that does the following:

rsync (Everyone seems to like -z, but it is much slower for me)

  • a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
  • H: preserves hard-links
  • A: preserves ACLs