Skip to content

Instantly share code, notes, and snippets.

View benjamintanweihao's full-sized avatar

Benjamin Tan Wei Hao benjamintanweihao

View GitHub Profile
@benjamintanweihao
benjamintanweihao / make_transparent.py
Last active May 20, 2018 15:47
Making an image transparent
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGBA)
image[np.all(image == [0, 0, 0, 255], axis=2)] = [0, 0, 0, 0]

Keybase proof

I hereby claim:

  • I am benjamintanweihao on github.
  • I am bentanweihao (https://keybase.io/bentanweihao) on keybase.
  • I have a public key ASAmpE_QvVG3NZzyRxlD0n5mQCg3vnApNkT3csQAKtXYQQo

To claim this, I am signing this object:

@benjamintanweihao
benjamintanweihao / environment.yml
Created March 4, 2018 12:47
conda env create -f environment.yml
name: pyimagesearch
channels:
- https://conda.anaconda.org/menpo
- conda-forge
dependencies:
- python==3.6
- numpy
- matplotlib
- jupyter
- opencv3
fn main() {
let s1 = "x=123, y = 345, rule = B21/S334";
let s2 = s1.replace(" ", "");
let s3 = s2.split(',').collect::<Vec<_>>();
let s4 = &s3[0..2];
let s5 = s4.iter()
.flat_map(|&x| x.split('=').collect::<Vec<_>>())
.collect::<Vec<_>>();
println!("x = {:?}", s5[1]);
println!("y = {:?}", s5[3]);
@benjamintanweihao
benjamintanweihao / bags_to_images.py
Created November 28, 2017 02:47
`python bags_to_images.py ~/Downloads/acq-camera-15h54-2016-12-12_14-53-58.bag output_images/ /camera_0`
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 Massachusetts Institute of Technology
"""Extract images from a rosbag.
"""
import os
import argparse
%%% File : gpb_eqc.erl
%%% Author : Thomas Arts <thomas.arts@quviq.com>
%%% Further developed by: Tomas Abrahamsson <tab@lysator.liu.se>
%%% Description : Testing protocol buffer implemented by Tomas Abrahamsson
%%% Created : 12 May 2010 by Thomas Arts
-module(gpb_eqc).
-include_lib("eqc/include/eqc.hrl").
-include("gpb.hrl").
@benjamintanweihao
benjamintanweihao / broadcaster.ex
Created May 4, 2017 16:27
Working example of 1-N Producer/Consumers, where each consumer receives the same thing.
defmodule Counter do
@moduledoc """
This is a simple producer that counts from the given
number whenever there is a demand.
"""
use GenStage
def start_link(initial) when is_integer(initial) do
GenStage.start_link(__MODULE__, initial, name: __MODULE__)
end
module Main where
main :: IO ()
main =
showcells glider
cls :: IO ()
cls =
putStr "\ESC[2J]"
@benjamintanweihao
benjamintanweihao / mocking_in_go.go
Created September 22, 2016 01:57
Mocking in Golang
type MockSlackClient2 struct {
PostMessageCalled bool
Message string
Entry *model.Entry
Status string
postMessage func(string, string, string)
postMessageWithMarkdown func(sting, string, string)
}
@benjamintanweihao
benjamintanweihao / darkroom.elisp
Created September 1, 2016 06:46
The beginnings of darkroom-mode
(set-window-margins (selected-window) 30 30)