Skip to content

Instantly share code, notes, and snippets.

View dc0d's full-sized avatar
💭
Some Sketches ¯\_(ツ)_/¯

Kaveh Shahbazian dc0d

💭
Some Sketches ¯\_(ツ)_/¯
View GitHub Profile
@dc0d
dc0d / baseXencoding
Created March 12, 2013 05:18
encode and decode from different number base; for example 9876543210 in base 36 would be 4jc8lii. I've learnt this from python code at http://stackoverflow.com/questions/1119722/base-62-conversion-in-python
func sample_usage() {
digits := "0123456789abcdefghijklmnopqrstuvwxyz" // base 36
var num int64 = 9876543210
fmt.Printf("input number is %d\n", num)
e := encode(num, digits)
fmt.Printf("encoded as %v\n", e)
d := decode(e, digits)
fmt.Printf("decoded as %v\n", d)
}
-module(server1).
-export([start/2, rpc/2]).
start(Name, Mod) ->
register(Name, spawn(fun() -> loop(Name, Mod, Mod:init()) end)).
rpc(Name, Request) ->
Name ! {self(), Request},
receive
{Name, Response} -> Response
-module(name_server).
-export([init/0, add/2, find/1, handle/2]).
-import(server1, [rpc/2]).
%% client routines
add(Name, Place) -> rpc(name_server, {add, Name, Place}).
find(Name) -> rpc(name_server, {find, Name}).
%% callback routines
init() -> dict:new().
-module(server2).
-export([start/2, rpc/2]).
start(Name, Mod) ->
register(Name, spawn(fun() -> loop(Name,Mod,Mod:init()) end)).
rpc(Name, Request) ->
Name ! {self(), Request},
receive
{Name, crash} -> exit(rpc);
-module(server3).
-export([start/2, rpc/2, swap_code/2]).
start(Name, Mod) ->
register(Name,
spawn(fun() -> loop(Name,Mod,Mod:init()) end)).
swap_code(Name, Mod) -> rpc(Name, {swap_code, Mod}).
rpc(Name, Request) ->
-module(name_server1).
-export([init/0, add/2, find/1, handle/2]).
-import(server3, [rpc/2]).
%% client routines
add(Name, Place) -> rpc(name_server, {add, Name, Place}).
find(Name) -> rpc(name_server, {find, Name}).
%% callback routines
init() -> dict:new().
-module(server4).
-export([start/2, rpc/2, swap_code/2]).
start(Name, Mod) ->
register(Name, spawn(fun() -> loop(Name,Mod,Mod:init()) end)).
swap_code(Name, Mod) -> rpc(Name, {swap_code, Mod}).
rpc(Name, Request) ->
Name ! {self(), Request},
@dc0d
dc0d / persian_calendar.ex
Created October 31, 2018 12:07
Persian Calendar Functions for Elixir
defmodule PersianCalendar do
@moduledoc """
for converting persian calendar to/from gregorian calendar
"""
@breaks [
-61,
9,
38,
199,
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dc0d
dc0d / 2021-w44-using-github-gists-for-blogging.md
Last active November 5, 2021 00:49
using github gists for blogging #blog

The idea of using gists for blogging sounds interesting. They can be searched like this for a user's blog gists. #blog should be appended to the title of the gist for it to show up in the search result.