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
@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)
@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.
#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;
#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;
@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)
{
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)
{-# 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.
@sajith
sajith / randomstr5.hs
Last active February 25, 2016 19:26
make a random text token, using MonadRandom and friends
module RandomStr5 where
-- uses `MonadRandom` package
import Control.DeepSeq (force)
import Control.Monad (liftM)
import Control.Monad.Random (evalRandIO, getRandoms)
import Data.List (nub)
import Data.Text (Text, pack)
module RandomStr4 where
-- uses `random` package
import Data.List as L
import Data.Text as T
import System.Random (RandomGen, newStdGen, randomRIO, randomRs)
------------------------------------------------------------------------
module RandomStr3 where
-- uses mwc-random for making random strings
import Data.List (nub)
import Data.Text as T (Text, pack)
import qualified Data.Vector.Unboxed as V (Vector, map, toList)
import Data.Word (Word8)
import System.Random.MWC (asGenST, uniformVector, withSystemRandom)