Skip to content

Instantly share code, notes, and snippets.

View zabirauf's full-sized avatar
👨‍💻
I may be slow to respond.

Zohaib Rauf zabirauf

👨‍💻
I may be slow to respond.
View GitHub Profile
@zabirauf
zabirauf / Codify Particle.lua
Created November 2, 2011 19:27
Codify Particle script. Use single touch to make particles go away from you. Use double touch to attract particles.
p={}
ps=800
touches={}
total=0
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
for i=0,ps do
p[i]= {x=math.random(WIDTH*10)/10,
y=math.random(HEIGHT*10)/10, ox=0.0, oy=0.0, vx=math.random(20)-10,
@zabirauf
zabirauf / sieve_server.erl
Last active August 29, 2015 14:03
A simple server which load balances a request among different process based on round robin algorithm. Written this to understand how could i do load balancing among different processes in Erlang
-module(sieve_server).
-export([sieve/1,start/1,sieve_loop/0,sieve_balancer/1,rpc/2,test/2,test_internal/2]).
test(Pid,Request) ->
spawn(sieve_server,test_internal,[Pid,Request]).
test_internal(Pid, Request) ->
receive
@zabirauf
zabirauf / gist:7000a1587ab42dd2b752
Created February 12, 2015 10:45
elixir_iis_web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
<httpPlatform stdoutLogEnabled="true" stdoutLogFile="elixir.log" startupTimeLimit="20" processPath="C:\inetpub\wwwroot\azure-elixir\run.bat"
arguments="">
<environmentVariables>
<environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%"/>
@zabirauf
zabirauf / ROP.ex
Created March 26, 2015 07:48
Railway Oriented Programming macros in Elixir
defmodule ROP do
defmacro try_catch(args, func) do
quote do
(fn ->
try do
unquote(args) |> unquote(func)
rescue
e -> {:error, e}
end
@zabirauf
zabirauf / expng.ex
Created July 23, 2015 08:32
PNG format Parser in Elixir
defmodule Expng do
defstruct [:width, :height, :bit_depth, :color_type, :compression, :filter, :interlace, :chunks]
def png_parse(<<
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A,
_length :: size(32),
"IHDR",
width :: size(32),
height :: size(32),
defmodule EphemeralShare.PeerChannel do
use Phoenix.Channel
require Logger
alias EphemeralShare.PeerManager
@doc """
Join the topic `peer:<GUID>` and add the peer in the peer manager
"""
def join("peer:" <> peer_id, _auth_msg, socket) do
defmodule EphemeralShare.PeerState do
require Logger
use GenServer
def start_link(peer_id) do
GenServer.start_link(__MODULE__, [peer_id], [name: {:global, peer_state_proc_id(peer_id)}])
end
def stop(peer_id) do
peer_id
@zabirauf
zabirauf / gulpfile.js
Created October 19, 2015 00:09
Gulpfile for a bower library
var gulp = require('gulp'),
gutil = require('gulp-util'),
eslint = require('eslint'),
babelify = require('babelify'),
source = require('vinyl-source-stream'),
browserify = require('browserify');
var paths = {
ALL: ['index.js', 'lib/*.js'],
JS: ['index.js', 'lib/*.js'],
@zabirauf
zabirauf / gulpfile.js
Created October 19, 2015 00:11
Gulpfile for a frontend in React + ES6
var gulp = require('gulp'),
gutil = require('gulp-util'),
babelify = require('babelify'),
source = require('vinyl-source-stream'),
browserify = require('browserify'),
watchify = require('watchify'),
browserSync = require('browser-sync').create();
var paths = {
HTML: 'src/index.html',
@zabirauf
zabirauf / messages_controller.ex
Last active June 15, 2016 05:06
Messages controller that receives message from user and sends it to Wit. Complete project at https://github.com/zabirauf/witai_elixir_weather_bot
defmodule EchoBot.MessagesController do
use MicrosoftBot.Phoenix.Controller
alias ExMicrosoftBot.Models.Message
def message_received(conn, %Message{} = message) do
session_id = message.conversationId
spawn fn ->
%{from: from, to: to, id: msgId} = message
context = %{"session" => %{