Skip to content

Instantly share code, notes, and snippets.

class BiDict(object):
'''
Maps both directions: key->value and value->key
Requires both keys and values are unique. If you pass duplication,
then key/value be overwritten and you get not what expected.
'''
origin = {} # counters the {key->key} case
bidict = {}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davesteele
davesteele / cache_dict.py
Last active October 19, 2023 14:23
Python LRU Caching Dictionary - a dict with a limited number of entries, removing LRU elements as necessary
from collections import OrderedDict
# >>> import cache_dict
# >>> c = cache_dict.CacheDict(cache_len=2)
# >>> c[1] = 1
# >>> c[2] = 2
# >>> c[3] = 3
# >>> c
# CacheDict([(2, 2), (3, 3)])
# >>> c[2]
@rossant
rossant / parallel_write.py
Created August 30, 2019 15:04
Write a NumPy array in parallel from multiple CPUs/processes, using shared memory. No copy/serialization involved. Pure Python/NumPy.
"""Write a NumPy array in parallel from multiple CPUs/processes, using shared memory."""
from contextlib import closing
import multiprocessing as mp
import os
import numpy as np
def _init(shared_arr_):
@DaniSancas
DaniSancas / neo4j_cypher_cheatsheet.md
Created June 14, 2016 23:52
Neo4j's Cypher queries cheatsheet

Neo4j Tutorial

Fundamentals

Store any kind of data using the following graph concepts:

  • Node: Graph data records
  • Relationship: Connect nodes (has direction and a type)
  • Property: Stores data in key-value pair in nodes and relationships
  • Label: Groups nodes and relationships (optional)
@cogmission
cogmission / QuickTest.py
Last active July 28, 2016 15:53
Example Use of Raw HTM Algorithms
'''
Created on Feb 8, 2015
@author: David Ray
'''
import numpy as np
from nupic.encoders.scalar import ScalarEncoder as ScalarEncoder
from nupic.algorithms.CLAClassifier import CLAClassifier as CLAClassifier
defmodule HammingBench do
use Benchfella
use Bitwise
@n Stream.repeatedly(fn -> Enum.random [0, 1] end)
|> Enum.take(100_000)
|> Enum.join
|> String.to_integer(2)
bench "CharlesO" do
@mrliptontea
mrliptontea / sublime-text-3-windows-shortcuts.md
Last active March 30, 2024 04:14 — forked from TheShrike/gist:6111200
Sublime Text 3 - Useful Shortcuts (Windows)

Sublime Text 3 - Useful Shortcuts (Windows)

General

Shortcut Description
Ctrl+Shift+P command prompt
Ctrl+Alt+P switch project
Ctrl+P go to file
Ctrl+G go to line
@BinaryMuse
BinaryMuse / README.md
Last active April 20, 2022 21:45
Elixir Map/HashDict Performance on Erlang OTP R17 vs R18
@neilgee
neilgee / sidr-init-content.js
Last active December 2, 2021 03:20
Sidr in WordPress
jQuery(document).ready(function($) {
$('#nav-toggle').sidr({
name: 'sidr-right',
side: 'right',
source: '#menu-short, .search-form, .site-title'
});
});