Skip to content

Instantly share code, notes, and snippets.

@elranu
elranu / encryption.ts
Created August 23, 2023 19:59 — forked from ChaoLiangSuper/encryption.ts
Stronger Encryption and Decryption in typescript
import crypto from 'crypto';
const ALGORITHM = 'aes-256-cbc';
const ENCODING = 'hex';
const IV_LENGTH = 16;
const KEY = process.env.ENCRYPTION_KEY!;
export const encrypt = (data: string) => {
const iv = crypto.randomBytes(IV_LENGTH);
const cipher = crypto.createCipheriv(ALGORITHM, new Buffer(KEY), iv);
@elranu
elranu / KmsSigner.ts
Created January 11, 2023 15:26 — forked from dangdennis/KmsSigner.ts
Typescripts ethers Signer using AWS KMS
// Code taken from https://gist.github.com/miguelmota/092da99bc8a8416ed7756c472dc253c4
import {
GetPublicKeyCommand,
KMSClient,
SignCommand,
} from "@aws-sdk/client-kms";
import { BigNumber, ethers, Signer, UnsignedTransaction } from "ethers";
import * as asn1 from "asn1.js";
import { AlchemyProvider } from "@ethersproject/providers";
@elranu
elranu / KmsSigner.js
Created January 11, 2023 15:26 — forked from miguelmota/KmsSigner.js
JavaScript ethers Signer using AWS KMS
const { BigNumber, Signer } = require('ethers')
const { keccak256, recoverAddress, joinSignature, resolveProperties, serializeTransaction, hashMessage, arrayify, defineReadOnly } = require('ethers/lib/utils')
const { KMSClient, GetPublicKeyCommand, SignCommand } = require('@aws-sdk/client-kms')
const asn1 = require('asn1.js')
const EcdsaPubKey = asn1.define('EcdsaPubKey', function () {
this.seq().obj(
this.key('algo').seq().obj(
this.key('a').objid(),
this.key('b').objid()
import { Injectable } from '@angular/core';
import * as firebase from 'firebase/app';
import { AngularFirestore, AngularFirestoreDocument, AngularFirestoreCollection } from 'angularfire2/firestore';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/switchMap';
@elranu
elranu / IHasAdmin.sol
Created June 21, 2019 20:49
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=undefined&optimize=false&gist=
pragma solidity 0.5.4;
contract IHasAdmin {
function isAdmin(address accountAddress) public view returns (bool);
}

Keybase proof

I hereby claim:

  • I am elranu on github.
  • I am elranu (https://keybase.io/elranu) on keybase.
  • I have a public key ASBtfIH0jSptVZCe2rjL_q7t3zZalnoH1eqfohC2u4P4Fgo

To claim this, I am signing this object:

@elranu
elranu / upsert-pr.ps1
Created February 13, 2019 17:50
github PR upsert
$Token = 'username:token89898989';
$Base64Token = [System.Convert]::ToBase64String([char[]]$Token);
$Headers = @{ AUTHORIZATION= "Basic $Base64Token" };
$Body = '{
"title": "Title",
"body": "Please merge this PR",
"head": "user:headBranch",
"base": "baseBranch"
@elranu
elranu / profile.ps1
Created January 2, 2019 17:56
Git submodules helper
function git-checkout-b() {
git checkout -b $args[0]
$cmd = 'git checkout -b ' + $args[0]
git submodule foreach $cmd
}
function git-checkout() {
git checkout $args[0]
$cmd = 'git checkout ' + $args[0]
git submodule foreach $cmd
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Extensions
{
public static class IEnumerableExtensions
{
/// <summary>
@elranu
elranu / transform.py
Created August 7, 2018 12:08
to yolo
import re
with open("labels_imagenes.csv", "r") as inp:
content = inp.read()
out = open('algo.csv', 'a')
out_dict = dict()
for line in content.split('\n')[1:-1]:
file, x, y, w, h, class_id = tuple(*re.findall(r'"(.+?),.+?x""""\:(\d+?)\b.+?y""""\:(\d+?)\b.+width"""":(\d+?)\b.+height"""":(\d+?)\b.+?idf"""":""""(.+?)"', line))
xmax = int(x) + int(w)