Skip to content

Instantly share code, notes, and snippets.

View sajith's full-sized avatar
😼
Why would I want to set a status on GitHub?

Sajith Sasidharan sajith

😼
Why would I want to set a status on GitHub?
View GitHub Profile
{-# LANGUAGE PackageImports #-}
module RandomStr6 where
-- Uses `crypto-api` package, but with `newGenIO` rather than
-- `newGen`; doesn't result in "*** Exception: NeedsInfiniteSeed"
--
-- extension `PackageImports` is needed because `Crypto.Random`
-- appears in `crypto-api`, `crypto-random`, and `cryptonite`
-- packages.
module RandomStr7 where
-- Couple more random token generators based on `random` package.
-- Do `:set +s` in ghci for quick timing checks.
import Control.DeepSeq (force)
import Control.Monad (replicateM, (>=>))
import Data.List (nub)
import Data.Text (Text, pack)
@sajith
sajith / threads.cc
Created February 14, 2017 22:55
C++11 threads
#include <iostream>
#include <thread>
#include <mutex>
#include <chrono>
#include <cstdlib>
std::mutex g_mutex;
void runner(int tid)
{
#include <chrono>
#include <cstdlib>
#include <iostream>
#include <list>
#include <mutex>
#include <sstream>
#include <thread>
static std::mutex g_mutex;
static const int NUM_THREADS = 10;
#include <chrono>
#include <iostream>
#include <list>
#include <mutex>
#include <random>
#include <sstream>
#include <thread>
static std::mutex g_mutex;
static const int NUM_THREADS = 10;
@sajith
sajith / uuid.cc
Created February 15, 2017 21:42
UUID generation
#include <iostream>
#include <uuid/uuid.h>
// This builds fine on both GNU/Linux (g++ 4.8, util-linux 2.23.2-33)
// and macOS Sierra (clang-800.0.42.1).
//
// On GNU/Linux, libuuid is provided by util-linux; macOS seems to be
// shipping things from e2fsprogs.
//
// No need of passing -luuid flag on macOS though.
@sajith
sajith / uuid2.cc
Created February 15, 2017 22:01
Rob BIGNUM number of UUIDs at a time from the universe
#include <iostream>
#include <vector>
#include <uuid/uuid.h>
int main()
{
std::vector<std::string> uuids;
static const int BIGNUM = 1000;
for (auto i = 0; i < BIGNUM; ++i)
#include <iostream>
#include <cassert>
#include <getopt.h>
#include <unistd.h>
#include <libmount/libmount.h>
#define _PATH_PROC_MOUNTINFO "/proc/self/mountinfo"
#define _PATH_PROC_MOUNTS "/proc/mounts"
@sajith
sajith / Makefile
Last active February 24, 2017 23:30
URL = https://www.kernel.org/pub/linux/utils/util-linux/v2.27/util-linux-2.27.tar.xz
LIBPATH = /tmp/util-linux-install
CXXFLAGS += -Wall -ggdb -std=c++11
CPPFLAGS += -I$(LIBPATH)/include
LIBMOUNT := $(LIBPATH)/lib/libmount.a
LIBBLKID := $(LIBPATH)/lib/libblkid.a
PROGRAM = mounts-test
#include <iostream>
#include <stdexcept>
#include <getopt.h>
#include "mounts.h"
// TODO: if a path is given, and nothing is mounted on it, find its
// parent.
// TODO: handle multiple inputs.