Skip to content

Instantly share code, notes, and snippets.

View malcolmgreaves's full-sized avatar

Malcolm Greaves malcolmgreaves

View GitHub Profile
@malcolmgreaves
malcolmgreaves / os_fp.py
Last active June 29, 2017 00:27
Listing all files from a given directory using functional programming.
from functools import partial
from operator import concat
from os.path import isfile
from fold import foldl
def _list_files_from(part, prev):
current = "%s/%s" % (prev, part)
if isfile(current):
UNDERSTANDING HASH FUNCTIONS
by Geoff Pike
Version 0.2 --- early draft --- comments and questions welcome!
References appear in square brackets.
1 INTRODUCTION
Hashing has proven tremendously useful in constructing various fast
data structures and algorithms. It is typically possible to simplify
@mcg1969
mcg1969 / circle.yml
Last active July 11, 2019 16:47
Cached Miniconda in CircleCI
machine:
environment:
MINICONDA: "$HOME/miniconda"
MINICONDA_PATH: "$MINICONDA/bin"
PATH: "$MINICONDA_PATH:$PATH"
CONDA: "$MINICONDA_PATH/conda"
ANACONDA: "$MINICONDA_PATH/anaconda"
# This ensures we don't accidentally pull in ~/.condarc
# if it happens to be there for some strange reason
CONDARC: "$MINICONDA/condarc.none"
@aparrish
aparrish / spacy_intro.ipynb
Last active August 9, 2023 01:41
NLP Concepts with spaCy. Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#include <cmath>
#include <iostream>
using std::cout;
using std::endl;
float quake3_hack(float number) {
float x2 = number * 0.5f;
float y = number;
long i = *(long*) & y;
@yossorion
yossorion / what-i-wish-id-known-about-equity-before-joining-a-unicorn.md
Last active April 7, 2024 22:55
What I Wish I'd Known About Equity Before Joining A Unicorn

What I Wish I'd Known About Equity Before Joining A Unicorn

Disclaimer: This piece is written anonymously. The names of a few particular companies are mentioned, but as common examples only.

This is a short write-up on things that I wish I'd known and considered before joining a private company (aka startup, aka unicorn in some cases). I'm not trying to make the case that you should never join a private company, but the power imbalance between founder and employee is extreme, and that potential candidates would

@malcolmgreaves
malcolmgreaves / BinomialHypothesisTest.scala
Last active November 8, 2016 17:34
Self-contained binomial hypothesis testing. Specifically 2-tailed test at a confidence interval of 95%.
object BinomialHypothesisTest {
def tTestBinomial(p1:Double, n1:Int, p2:Double, n2:Int): TtestRes = {
val k = (n1*p1 + n2*p2) / (n1 + n2).toDouble
val z = (p1 - p2) / math.sqrt( k*(1 - k) * (1 / n1.toDouble + 1 / n2.toDouble) )
if(z > scoreForTwoTailed95CiPval)
RejectNull
else
FailToReject
}

Recovering deleted files in Ubuntu with ext4 filesystem

Recently, I deleted some files by mistake in a Ubuntu machine with an ext4 fs. These notes document the steps I took to get them back.

Important

  • this procedure assumes that the partition that contained the deleted files is different from the root partition, as that was the scenario with which I had to deal (deleted files were in my home dir). The procedure needs that the partition that contained the files is unmounted, so if the deleted files were in the root partition, the process would be a bit different (e.g. storing the fs journal in a USB stick, using a live CD/USB to boot and issue the commands, etc.)
  • if something is not clear, you need more information, etc. check the sources below

With that out the way, let's begin.

@bastman
bastman / docker-cleanup-resources.md
Created March 31, 2016 05:55
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

object DiffieHellmanMerkle {
import java.math.BigInteger
import scala.language.implicitConversions
import scala.util.Random
def main(args: Array[String]): Unit =
println(
diffieHellmanMerkle(generator = 3, modulus = 17, alicePrivateKey = 54, bobPrivateKey = 24)
)