Skip to content

Instantly share code, notes, and snippets.

View imranismail's full-sized avatar

Imran Ismail imranismail

View GitHub Profile
@imranismail
imranismail / README.md
Created July 10, 2015 06:45
How to setup middleman on OSX 10.10

Getting Started

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Install rbenv and ruby-build
@imranismail
imranismail / UrlParser.php
Last active September 17, 2015 10:43
UrlParser.php
<?php
class UrlParser
{
/**
* The url to be parsed
* @param String $url
*/
public function __construct($url)
{
@imranismail
imranismail / spectacle_app_extractor.sh
Created September 26, 2015 05:23
Spectacleapp Preference Extractor
for key in MoveToPreviousThird MoveToRightDisplay MakeLarger MoveToRightHalf MakeSmaller MoveToTopDisplay MoveToBottomDisplay MoveToTopHalf MoveToBottomHalf MoveToUpperLeft MoveToCenter MoveToUpperRight MoveToFullscreen MoveToLeftDisplay MoveToLeftHalf MoveToLowerLeft RedoLastMove MoveToLowerRight MoveToNextDisplay MoveToNextThird MoveToPreviousDisplay UndoLastMove; do
printf "defaults write com.divisiblebyzero.Spectacle ${key} -data ";
defaults read com.divisiblebyzero.Spectacle ${key} | sed 's/[^0-9a-f]//g';
done
@imranismail
imranismail / registry_test.exs
Created October 31, 2015 09:38
Sharing context across tests
defmodule KeyVal.RegistryTest do
use ExUnit.Case, async: false
setup do
{:ok, registry} = KeyVal.Registry.start_link
{:ok, registry: registry}
end
test "spawns bucket", %{registry: registry} do
assert {:ok, _bucket} = KeyVal.Registry.create(registry, "shopping")
@imranismail
imranismail / 0_reuse_code.js
Created February 18, 2016 10:32
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@imranismail
imranismail / README.md
Created April 8, 2016 15:26
Dynamic Function Capture

Normally we would capture using the & syntax eg: &List.first/1 if we know exactly what to capture. How would I capture the function if the module name and function name is stored in a variable example:

module_name = List
function = :size
arity = 2

Now how would I capture the function dynamically?

@imranismail
imranismail / README.md
Created August 25, 2016 18:59 — forked from ahmadshah/README.md
Ecto Soft Delete

Soft Delete Ecto Repo

The goal is to support soft delete functionality in Ecto.Repo. With the suggestion by @imranismail, another repo is created and the remaining functionalities are delegate to the original MyApp.Repo.

The new repo get/2 and all/1 functions will exclude the soft deleted record by default. delete/1 and delete_all/1 will update the delete_at column by default instead of deleting.

Example

MyApp.Repo.get(MyApp.User, 1) //will return nil if record is in soft delete state
@imranismail
imranismail / README.md
Last active May 19, 2021 17:21
Dynamic Elixir Node Discovery on Kubernetes

Dynamic Elixir Node Discovery on Kubernetes

One way one would do it i to connect nodes together by having the sys.config/vm.args as suggested by chrismccord here

However, when deploying to platform such as Kubernetes or AWS ElasticBeanstalk whereby the cluster is elastic and the IPs that are attached to the nodes are ephemeral, you probably don't want to update sys.config/vm.args everytime you do a deployment now would you.

Now, to solve this one would need to use a Discovery Service such as Consul/etcd/Zookeeper, I opt to use Kubernetes as it's one of the best PaaS for containerized apps available right now and also has a RESTful API for querying resources such as node IPs.

How it's done is that the Iris.Kubernetes process will poll the API endpoint every 5 seconds for new IPs that are available in the cluster and attempt a connection.

@imranismail
imranismail / docker-compose.yml
Last active October 20, 2016 05:22
A quick development environment for Elixir apps using Docker Compose
version: '2'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
volumes:
- ./.data/postgres:/var/lib/postgresql/data
@imranismail
imranismail / docker-compose.yml
Last active October 27, 2016 18:52 — forked from ahmadshah/docker-compose.yml
elixir docker
version: '2'
services:
db:
image: mariadb
restart: always
volumes:
- ./docker/data/mysql:/var/lib/mysql
ports:
- "3306:3306"