Skip to content

Instantly share code, notes, and snippets.

View shankardevy's full-sized avatar

Shankar Dhanasekaran shankardevy

View GitHub Profile

Keybase proof

I hereby claim:

  • I am shankardevy on github.
  • I am shankardevy (https://keybase.io/shankardevy) on keybase.
  • I have a public key ASAdzhd70kj5FV72DJq15nV4-E6HEf9XNZ7kngbKCC6UIgo

To claim this, I am signing this object:

@shankardevy
shankardevy / .c
Created January 19, 2018 08:05 — forked from azhaganandhan/.c
#include <Wire.h>
void setup() {
// put your setup code here, to run once:
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600);
}
int reading = 0;
@shankardevy
shankardevy / generate_functions.ex
Last active October 25, 2016 18:02
Generating functions based on macro
defmodule LearnMacro do
defmacro gen_func(func_name, arguments, do: expression) do
quote do
def unquote(:"#{func_name}")(unquote_splicing(arguments)), do: unquote(expression)
end
end
end
@shankardevy
shankardevy / multiple-of-3-or-5-or-both.ex
Created October 25, 2016 16:08
A program that prints out the numbers 1 to 100 (inclusive). If the number is divisible by 3, print Crackle instead of the number. If it's divisible by 5, print Pop. If it's divisible by both 3 and 5, print CracklePop.
defmodule Math do
def map_number(number) do
case { rem(number,3), rem(number,5) } do
{ 0, 0 } ->
"CradlePop"
{ 0, _ } ->
"Cradle"
{ _, 0 } ->
"Pop"
{ _, _ } ->
@shankardevy
shankardevy / marco_in_tamil.ex
Created October 8, 2015 16:36
Macro in Tamil language
defmodule Tamil do
defmacro கூட்டு(a + b) do
a + b
end
defmacro போடு(x) do
IO.puts x
end
end
@shankardevy
shankardevy / event_handler.ex
Created September 29, 2015 10:37
Where to add the event handlers?
defmodule KV.Supervisor do
use Supervisor
def start_link do
Supervisor.start_link(__MODULE__, :ok)
end
@manager_name KV.EventManager
@registry_name KV.Registry
defmodule Snapshot.Server do
@moduledoc """
Provides functions and workers for getting snapshots from the camera
Workers are run in the background getting snapshots from the camera
using the frequency for the given camera.
Functions can be called from other places to get snapshots manually.
"""
@shankardevy
shankardevy / supervisor.ex
Last active September 14, 2015 07:49
Supervisor
defmodule MyApp.Worker.Supervisor do
use Supervisor
def start_link do
Supervisor.start_link(__MODULE__, [], name: __MODULE__)
end
def init(_) do
Task.start_link(&MyApp.Worker.Supervisor.initiate_workers/0)
@shankardevy
shankardevy / gist:535f48fb4583425049c3
Created June 29, 2015 15:57
Sinatra app for testing digest auth
# sinatra app
# config.ru
# To start the server, run
# $ rackup config.ru
# visit localhost:9292/digest
require 'sinatra/base'
def fetch(url, {:basic, auth}) do
[username, password] = String.split(auth, ":")
request = HTTPotion.get(url, [basic_auth: {username, password}])
request.body
end
def fetch(url, {:digest, auth}) do
digest_request = Porcelain.shell("curl --max-time 15 --digest --user '#{auth}' #{url}")
digest_request.out
end