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 / 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%"/>
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 / 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 / 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 / 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" => %{
@zabirauf
zabirauf / weather_conversation_action.ex
Created June 15, 2016 05:12
Weather conversation Wit.ai actions for the story created to get weather information. Complete project at https://github.com/zabirauf/witai_elixir_weather_bot
defmodule EchoBot.WeatherConversationAction do
use Wit.Actions
alias Wit.Models.Response.Converse, as: WitConverse
alias ExMicrosoftBot.Client
def say(_session_id, %{} = context, %WitConverse{msg: msg_to_send} = message) do
%{"session" => %{"from" => to, "to" => from, "msgId" => msgId}} = context
message_to_send = %{from: from, to: to, replyToMessageId: msgId, text: msg_to_send}
Client.send_message(get_bot_auth_data(), message_to_send)
@zabirauf
zabirauf / SuaveBootstrapFlynn.fs
Last active October 16, 2016 21:30
A F# Suave web app that outputs HTML
module SuaveBootstrapFlynn
open Suave
open Suave.Successful
open Suave.Web
open Suave.Operators
open Suave.Filters
open System
open System.Net
@zabirauf
zabirauf / FunctionBinder.ts
Last active March 8, 2017 07:42
And example for FunctionBinder class
interface CurriedFunction2<T1, T2, R> {
(t1: T1): (t2: T2) => R;
(t1: T1, t2?: T2): R;
}
interface CurriedFunction3<T1, T2, T3, R> {
(t1: T1): CurriedFunction2<T2, T3, R>;
(t1: T1, t2?: T2): (t3: T3) => R;
(t1: T1, t2?: T2, t3?: T3): R;
}