Skip to content

Instantly share code, notes, and snippets.

/*! Top K elements of an unordered list
There are 3 ways to get the top k elements from an unsorted list.
1. Build a heap with all the elements and pop k times
2. Sort the whole list and return a slice from the end
3. Quick select k elements
Naively, I would expect 1 to be slowest, 2 to be faster and 3 the fastest.
@jaseemabid
jaseemabid / spectre.c
Created January 4, 2018 04:42 — forked from ErikAugust/spectre.c
Spectre example code
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef _MSC_VER
#include <intrin.h> /* for rdtscp and clflush */
#pragma optimize("gt",on)
#else
#include <x86intrin.h> /* for rdtscp and clflush */
#endif
@jaseemabid
jaseemabid / adler.hs
Created February 26, 2017 10:04
Adler32 implementation in C and Haskell
adler32 :: String -> Int
adler32 = helper 1 0
where
helper a b (x:xs) = helper a' b' xs
where a' = (a + (ord x .&. 0xff)) `mod` base
b' = (a' + b) `mod` base
base = 65521
helper a b _ = (b `shiftL` 16) .|. a

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

Keybase proof

I hereby claim:

  • I am jaseemabid on github.
  • I am jaseemabid (https://keybase.io/jaseemabid) on keybase.
  • I have a public key whose fingerprint is 0D01 F83F 9C88 2B6F 42B0 B93B FE8B A47C AF68 AB61

To claim this, I am signing this object:

@jaseemabid
jaseemabid / lisp.org
Last active February 29, 2016 18:42
Slides of the talk "A micro manual for LISP - Not the whole truth"

Hello!

I’m Jaseem Abid

2009 - ‘13 Batch @jaseemabid gh/jaseemabid

A micro manual for LISP - Not the whole truth

@jaseemabid
jaseemabid / prof.erl
Created February 19, 2016 11:04
Run the MFA, but log the time taken for it as well.
%% @doc Run the MFA, but log the time taken for it as well.
prof(M, F, A) ->
Note = atom_to_list(M) ++ ":" ++ atom_to_list(F),
prof(Note, M, F, A).
prof(Note, M, F, A) ->
S = os:timestamp(),
Result = apply(M, F, A),
E = os:timestamp(),
Diff = timer:now_diff(E, S)/1.0e6,
@jaseemabid
jaseemabid / time.hs
Created October 30, 2015 13:43
Get current time as an integer
-- Definitely not the best way to get current time as integer
currentPosixTime <- (getCurrentTime >>= return . utcTimeToPOSIXSeconds)
let currentTime = (round (read (init $ show(currentPosixTime)) :: Float) :: Integer)
import logging
import time
logger = logging.getLogger(__name__)
def useful():
logger.debug('Hello from webapplib!')
time.sleep(0.01)
;;; auto-remove.el --- Auto remove unused functions in python
;;; Commentary:
;; Uses external tool autoflake to remove unused imports from a Python file.
;;; Code:
(defcustom python-autoflake-path (executable-find "autoflake")
"Autoflake executable path.