Skip to content

Instantly share code, notes, and snippets.

View minhajuddin's full-sized avatar
⌨️
Beep boop, beep boop

Khaja Minhajuddin minhajuddin

⌨️
Beep boop, beep boop
View GitHub Profile
@minhajuddin
minhajuddin / ticker.ex
Created October 26, 2016 21:05
A ticker for elixir, which emits a tick event for every interval
defmodule Ticker do
require Logger
# public api
def start(recipient_pid, tick_interval, duration \\ :infinity) do
# Process.monitor(pid) # what to do if the process is dead before this?
# start a process whose only responsibility is to wait for the interval
ticker_pid = spawn(__MODULE__, :loop, [recipient_pid, tick_interval, 0])
# and send a tick to the recipient pid and loop back
send(ticker_pid, :send_tick)
schedule_terminate(ticker_pid, duration)
@minhajuddin
minhajuddin / poolboy_demo.ex
Created October 21, 2016 05:12 — forked from henrik/poolboy_demo.ex
Example of using Poolboy in Elixir to limit concurrency (e.g. of HTTP requests).
defmodule HttpRequester do
use GenServer
def start_link(_) do
GenServer.start_link(__MODULE__, nil, [])
end
def fetch(server, url) do
# Don't use cast: http://blog.elixirsips.com/2014/07/16/errata-dont-use-cast-in-a-poolboy-transaction/
timeout_ms = 10_000
" settings
colorscheme molokai
let loaded_matchparen=1 " don't automatically highlight the matching parens
let mapleader = ' '
let maplocalleader = ' '
set autowriteall " autosave files
set background=dark
set clipboard=unnamedplus " Yanks go on clipboard
set cmdheight=2
@minhajuddin
minhajuddin / calc.html
Created September 2, 2016 11:19
html session 04
<!doctype html>
<div id='output'>Output: </div>
<input type="text" id="op1" placeholder="Input 1" />
<br>
<input type="text" id="op2" placeholder="Input 2" />
<br>
<button onclick="calculate()">Add</button>
@minhajuddin
minhajuddin / calc.html
Created September 1, 2016 10:06
Simple Calculator
<!doctype html>
<div id='output'>Output: </div>
<input type="text" id="op1" placeholder="Input 1" />
<br>
<input type="text" id="op2" placeholder="Input 2" />
<br>
<button onclick="calculate()">Add</button>
@minhajuddin
minhajuddin / README.md
Created July 24, 2016 15:07 — forked from blackjid/README.md
How configure your raspberry pi with dashing to have a awesome dashboard

Raspberry pi dashboard

This is what we did to setup a few dashboards at platanus

You'll need

  • Raspberry Pi
  • Dashing Service
  • Wifi stick (optional)
@minhajuddin
minhajuddin / letsencrypt.md
Created July 12, 2016 18:45 — forked from xrstf/letsencrypt.md
Let's Encrypt on Ubuntu 14.04, nginx with webroot auth

Let's Encrypt on Ubuntu 14.04, nginx with webroot auth

This document details how I setup LE on my server. Firstly, install the client as described on http://letsencrypt.readthedocs.org/en/latest/using.html and make sure you can execute it. I put it in /root/letsencrypt.

As it is not possible to change the ports used for the standalone authenticator and I already have a nginx running on port 80/443, I opted to use the webroot method for each of my domains (note that LE does not issue wildcard certificates by design, so you probably want to get a cert for www.example.com and example.com).

Configuration

For this, I placed config files into etc/letsencrypt/configs, named after <domain>.conf. The files are simple:

// run it using
// node loop_array_length.js
// =>
// bad 7 ms
// good 5 ms
var a = []
for (var i = 0; i < 10000000; i++) {
a.push(i);
}
@minhajuddin
minhajuddin / phoenix-app.service
Last active June 26, 2016 21:04 — forked from edevil/phoenix-app.service
systemd service for phoenix framework release (exrm)
# Phoenix Framework - A productive web framework that does not compromise speed and maintainability
[Unit]
Description=Phoenix Framework ISControl Application
After=network.target
[Service]
Type=simple
User=deployer
RemainAfterExit=yes
@minhajuddin
minhajuddin / flatten.exs
Created May 20, 2016 08:53
Flatten a list
defmodule MyList do
# [ 1 , 2, 3, [ 1, 2]]
def flatten(list) do
do_flatten(list, [])
end
def do_flatten([h|t], acc_list) when is_list(h) do
# this may be expensive!
do_flatten(h ++ t, acc_list)
end