Skip to content

Instantly share code, notes, and snippets.

View neeraj9's full-sized avatar
🎯
Focusing

Neeraj neeraj9

🎯
Focusing
  • Microsoft
View GitHub Profile
@neeraj9
neeraj9 / kqueue_server_listen_sock_behaviour
Created August 21, 2015 08:02
kqueue gives back write event on a listen socket eventhough I registered for read
/* http://doc.geoffgarside.co.uk/kqueue/files/chatserv.c */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/event.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@neeraj9
neeraj9 / rumprun-x86_64-workaround.patch
Created September 2, 2015 17:00
Workaround for x86_64 target for red zone
diff --git a/build-rr.sh b/build-rr.sh
index 8b5bdf4..3be2a0b 100755
--- a/build-rr.sh
+++ b/build-rr.sh
@@ -217,6 +217,8 @@ EOF
# -mno-red-zone.
if [ "${PLATFORM}" = "xen" -a "${MACHINE_ARCH}" = "x86_64" ]; then
echo "CFLAGS+=-mno-red-zone" >> ${RUMPTOOLS}/mk.conf
+ elif [ "${PLATFORM}" = "hw" -a "${MACHINE_ARCH}" = "x86_64" ]; then
+ echo "CFLAGS+=-mno-red-zone" >> ${RUMPTOOLS}/mk.conf
@neeraj9
neeraj9 / backtrace.c
Created October 3, 2015 05:48
c code to print stack trace when program segfaults
/**
* This source file is used to print out a stack-trace when your program
* segfaults. It is relatively reliable and spot-on accurate.
*
* This code is in the public domain. Use it as you see fit, some credit
* would be appreciated, but is not a prerequisite for usage. Feedback
* on it's use would encourage further development and maintenance.
*
* Due to a bug in gcc-4.x.x you currently have to compile as C++ if you want
* demangling to work.
@neeraj9
neeraj9 / elixir_to_erlang.erl
Created December 18, 2017 22:06 — forked from habibutsu/elixir_to_erlang.erl
Elixir to Erlang
% erl -pa /usr/share/elixir/1.0.5/lib/*/ebin -elixir ansi_enabled true
application:ensure_all_started(elixir),
rr("/usr/share/elixir/1.0.5/lib/elixir/src/elixir.hrl").
% A simplified version of 'Elixir.Code':eval_string/2
% https://github.com/elixir-lang/elixir/blob/v1.2.0/lib/elixir/lib/code.ex#L159
EvalString = fun(String, Binding) ->
% Converts a given string (char list) into quote expression
% https://github.com/elixir-lang/elixir/blob/v1.2.0/lib/elixir/src/elixir.erl#L252
@neeraj9
neeraj9 / beamparticle_adder.java
Created January 28, 2018 19:34
BeamParticle Java 8 Dynamic function for adding two numbers
#!java
import com.ericsson.otp.erlang.OtpErlangObject;
import com.ericsson.otp.erlang.OtpErlangLong;
() -> new Object() {
public OtpErlangLong main(OtpErlangLong aLong, OtpErlangLong bLong) {
java.math.BigInteger a = aLong.bigIntegerValue();
java.math.BigInteger b = bLong.bigIntegerValue();
java.math.BigInteger result = a.add(b);
return new OtpErlangLong(result);
@neeraj9
neeraj9 / beamparticle_http_post_json.java
Last active February 9, 2019 22:28
BeamParticle Java 8 Dynamic function for /post/ HTTP POST JSON handler
#!java
// Sample Java 8 function to return what was passed in as the first argument.
// Notice that this template works for the /post/<thisfun> interface, where
// json input is passed in the first argument postBody, while the response
// is a binary or a string, which must be json as well.
import java.nio.charset.StandardCharsets;
import com.ericsson.otp.erlang.OtpErlangAtom;
import com.ericsson.otp.erlang.OtpErlangBinary;
@neeraj9
neeraj9 / beamparticle_http_post_json.py
Last active February 9, 2019 22:26
BeamParticle Python 3 Dynamic function for /post/ HTTP POST JSON handler
#!python
# Sample Python 3 function to return what was passed in as the first argument.
# Notice that this template works for the /post/<thisfun> interface, where
# json input is passed in the first argument postBody, while the response
# is a binary or a string, which must be json as well.
from Pyrlang import term
import json
def main(data_binary, context_binary):
@neeraj9
neeraj9 / beamparticle_http_post_json.ex
Last active February 9, 2019 22:27
BeamParticle Elixir Dynamic function for /post/ HTTP POST JSON handler
#!elixir
# Sample Python 3 function to return what was passed in as the first argument.
# Notice that this template works for the /post/<thisfun> interface, where
# json input is passed in the first argument postBody, while the response
# is a binary or a string, which must be json as well.
fn (body, context) ->
decoded_map = :jiffy.decode(body, [:return_maps])
# TODO process decoded_map
result = decoded_map
@neeraj9
neeraj9 / beamparticle_http_post_json.erl
Last active February 9, 2019 22:28
BeamParticle Erlang Dynamic function for /post/ HTTP POST JSON handler
#!erlang
%% Sample Erlang (OTP-20) function to return what was passed in as the first argument.
%% Notice that this template works for the /post/<thisfun> interface, where
%% json input is passed in the first argument postBody, while the response
%% is a binary or a string, which must be json as well.
fun (Body, Context) ->
DecodedMap = jiffy:decode(Body, [return_maps]),
%% TODO process decoded_map
Result = DecodedMap,
@neeraj9
neeraj9 / beamparticle_http_post_json.efe
Created February 6, 2018 02:46
BeamParticle Efene Dynamic function for /post/ HTTP POST JSON handler
#!efene
#_ "A sample efene code to return what was passed in as the first argument."
#_ "Notice that this template works for the /post/<thisfun> interface, where"
#_ "json input is passed in the first argument postBody, while the response"
#_ "is a binary or a string, which must be json as well."
#_ ""
#_ "Read about Efene at efene.org"
#_ "see http://efene.org/language-introduction.html"
#_ ""
#_ "Author: Neeraj Sharma <neeraj.sharma@alumni.iitg.ernet.in>"