Skip to content

Instantly share code, notes, and snippets.

View jeshan's full-sized avatar
🏠
Working from home

Jeshan Giovanni BABOOA jeshan

🏠
Working from home
  • Independent
  • Mauritius
View GitHub Profile
@jeshan
jeshan / get-lambda-event-source.js
Last active June 23, 2023 13:01
AWS Lambda: Determine Event Source from event object. Note that this is an approximation as anybody can send a payload that resembles the real thing.
function getLambdaEventSource(event) {
if (event.Records && event.Records[0].cf) return 'isCloudfront';
if (event.configRuleId && event.configRuleName && event.configRuleArn) return 'isAwsConfig';
if (event.Records && (event.Records[0].eventSource === 'aws:codecommit')) return 'isCodeCommit';
if (event.authorizationToken === "incoming-client-token") return 'isApiGatewayAuthorizer';
if (event.StackId && event.RequestType && event.ResourceType) return 'isCloudFormation';
@jeshan
jeshan / extractgc.sh
Created July 17, 2021 23:18 — forked from xigh/extractgc.sh
Extracting LLVM bitcode from ELF files generated with -fembed-bitcode.
#!/bin/sh
if [ "*$1" == "*" ]; then
echo "usage: extract.sh src dst"
fi
if [ "*$2" == "*" ]; then
echo "usage: extract.sh src dst"
fi
@jeshan
jeshan / cdk-profile-plugin.js
Last active April 28, 2022 20:01
How to select AWS profiles per account in AWS CDK
const { CredentialProviderChain } = require('aws-sdk');
const AWS = require('aws-sdk');
const accountProvider = require('./account-provider');
let getEnv = function(accountId) {
// TODO: insert logic to get your desired profile name
return profileName;
};
let getProvider = async (accountId, mode) => {
@jeshan
jeshan / towctrans.lo.ll
Created May 27, 2021 21:14
towctrans from musl libc in LLVM IR assembly format
; ModuleID = 'towctrans.lo'
source_filename = "src/ctype/towctrans.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-alpine-linux-musl"
%struct.__locale_struct = type opaque
@casemap.mt = internal constant [3 x i32] [i32 2048, i32 342, i32 57], align 4, !dbg !0
@rules = internal constant [240 x i32] [i32 0, i32 8193, i32 -8192, i32 1949440, i32 190208, i32 30976, i32 9218, i32 257, i32 -256, i32 0, i32 513, i32 -512, i32 -50943, i32 -59392, i32 -30975, i32 -76800, i32 49920, i32 53761, i32 52737, i32 52481, i32 20225, i32 51713, i32 51969, i32 52993, i32 24832, i32 54017, i32 53505, i32 41728, i32 54529, i32 33280, i32 54785, i32 55809, i32 55553, i32 56065, i32 14336, i32 3, i32 -20224, i32 -24831, i32 -14335, i32 2369538, i32 0, i32 257, i32 -256, i32 -52480, i32 -55808, i32 -33279, i32 2763521, i32 -41727, i32 2762753, i32 2768640, i32 -49919, i32 17665, i32 18177, i32 2760448, i32 2759680, i32 2760192, i32 -53760, i32 -52736, i32 -517
; ModuleID = 'crt1.o'
source_filename = "crt/crt1.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-alpine-linux-musl"
module asm ".text "
module asm ".global _start "
module asm "_start: "
module asm "\09xor %rbp,%rbp "
module asm "\09mov %rsp,%rdi "
@jeshan
jeshan / state.pl
Created April 3, 2021 18:31
Pure way for tracking state of variables in Prolog
% get_value(Value, History)
% History tracks values set for variable
get_value(Val, List) :-
nonvar(List), % just so that fails when nothing added yet.
nextto(t(Val), Var, List),
var(Var),
!.
available_spot(X, History) :-
@jeshan
jeshan / ruby.dockerfile
Last active April 3, 2021 18:15
Demonstrates bug https://github.com/oracle/truffleruby/issues/2247 . v1 builds successfully but v2 throws exception in issue
FROM buildpack-deps:buster
# skip installing gem documentation
RUN set -eux; \
mkdir -p /usr/local/etc; \
{ \
echo 'install: --no-document'; \
echo 'update: --no-document'; \
} >> /usr/local/etc/gemrc
@jeshan
jeshan / hex.pl
Last active April 3, 2021 11:06
Bi-directional conversion between hex strings and numbers in Prolog
:- use_module(library(clpfd)).
hex_number(Hex, Num) :-
ground(Hex),
!,
string_concat("0x", Hex, HexStr),
number_string(Num, HexStr).
hex_number(Hex, Num) :-
var(Hex),
@jeshan
jeshan / cognito.yaml
Created February 4, 2018 08:18 — forked from singledigit/cognito.yaml
Create a Cognito Authentication Backend via CloudFormation
AWSTemplateFormatVersion: '2010-09-09'
Description: Cognito Stack
Parameters:
AuthName:
Type: String
Description: Unique Auth Name for Cognito Resources
Resources:
# Creates a role that allows Cognito to send SNS messages
@jeshan
jeshan / mri.dockerfile
Created February 2, 2021 20:43
Gist to reproduce Ruby MRI compilation issue with Sulong
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y make libedit* tree
WORKDIR /app
COPY graalvm-ce-java11-linux-amd64-21.0.0.tar.gz graalvm.tar.gz
COPY llvm-toolchain-installable-java11-linux-amd64-21.0.0.jar llvm-toolchain.jar
RUN tar zxvf graalvm.tar.gz