Skip to content

Instantly share code, notes, and snippets.


Collins Muriuki collinsmuriuki

View GitHub Profile
collinsmuriuki /
Created Nov 10, 2020
Parse http request with httparse
use std::net::tcplistener;
use std::io::read;
use httparse;
fn main() {
let listener = tcplistener::bind("").unwrap();
println!("server running on http://localhost:9000");
loop {
collinsmuriuki / package.json
Last active Nov 13, 2020
Handy dandy TypeORM cli scripts that work for a Nest.js project with an ormconfig.ts module
View package.json
"scripts": {
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config src/ormconfig.ts",
"typeorm:generate": "npm run typeorm migration:generate -- --name",
"typeorm:create": "npm run typeorm migration:create -- --name",
"typeorm:revert": "npm run typeorm migration:revert",
"typeorm:run": "npm run typeorm migration:run"

Curling a graphql endpoint

curl \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"query": "{allCountriesStats {country}}"}' \ | python -m json.tool
View purge_node_modules
# Linux/ Mac
cd documents
find . -name "node_modules" -type d -prune -print | xargs du -chs
# Windows
cd documents
FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" echo %d"

Keybase proof

I hereby claim:

  • I am collinsmuriuki on github.
  • I am collinsmuriuki ( on keybase.
  • I have a public key ASBG7gHHWMBMvXmmjOhXqose9Q9ON5Sspv9f67-57fp8VAo

To claim this, I am signing this object:

collinsmuriuki /
Last active Sep 19, 2020
An implementation of the State pattern in Rust
pub struct Post {
state: Option<Box<dyn State>>,
content: String,
impl Post {
pub fn new() -> Post {
Post {
state: Some(Box::new(Draft {})),
content: String::new(),
collinsmuriuki /
Last active Sep 11, 2020
How to check nodejs memory limit

Overwriting default memory allocation

Set --max-old-space-size to the value in megabytes of how large you would like the heap size:

node --max-old-space-size=4096 v8.js
collinsmuriuki /
Created Sep 11, 2020
A mock GUI implementation to demonstrate Trait Objects
pub trait Draw {
fn draw(&self);
pub struct Screen {
pub components: Vec<Box<dyn Draw>>,
impl Screen {
pub fn run(&self) {
collinsmuriuki /
Last active Sep 1, 2020
Mutex and Arc: How Mutex, a smart pointer is used to allow access to data from one thread at a time and introducing multiple ownership rules of Rc<T> in multithreaded scenarios using a similar smart pointer Arc<T>>
use std::sync::{Mutex,Arc}; // mutual exclusion
use std::thread;
use std::rc::Rc;
// Mutex in single threaded scenarios
pub fn start_mutex() {
let m = Mutex::new(String::new());
let mut num = m.lock().unwrap();
collinsmuriuki /
Last active Aug 28, 2020
Threads and channels
use std::thread;
use std::time::Duration;
use std::sync::mpsc; // multiple producer, single consumer
pub fn threads1() {
thread::spawn(|| {
for i in 1..10 {
println!("hi number {} from the spawned thread!", i);
You can’t perform that action at this time.