Skip to content

Instantly share code, notes, and snippets.

View alisinabh's full-sized avatar

Alisina Bahadori alisinabh

View GitHub Profile
@alisinabh
alisinabh / opposite_math_macro.exs
Last active December 16, 2016 00:07
Creating a macro with elixir to vice versa nested math operations
defmodule OppositeMath do
@moduledoc """
This module helps with oppositting nested math formuals like 2 + 5 * 4 + 6 => 2 - 5 / 4 - 6 for sake of learning elixir macros
"""
@doc """
This macro opposites all math symbols in a formula
## Examples
iex> OppositeMath.opposite 1+1
@alisinabh
alisinabh / decrease-brightness.sh
Created April 21, 2017 22:00
X window selective brightness control - using Xrandr and awk
BRIGHTNESS=`xrandr --verbose | grep -i brightness | cut -f2 -d ' ' | head -n1`
NEW_BRIGHTNESS=`awk '{print $1-$2}' <<<"$BRIGHTNESS 0.05"`
echo $NEW_BRIGHTNESS
xrandr --output DVI-I-1 --brightness $NEW_BRIGHTNESS
xrandr --output DVI-I-2 --brightness $NEW_BRIGHTNESS
@alisinabh
alisinabh / Dockerfile
Created August 12, 2019 01:25
Stolon postgis postgresql
# Source image of stolon to add postgis to
FROM sorintlab/stolon:v0.13.0-pg10
# Since we are using a pg10 image of stolon we will install postgresql-10-postgis-x.x
RUN apt-get update && apt-get install -y postgresql-10-postgis-2.4
@alisinabh
alisinabh / BasicERC20.sol
Created December 3, 2020 23:01 — forked from giladHaimov/BasicERC20.sol
Basic ERC20 implementation
pragma solidity ^0.4.19;
contract ERC20Basic {
string public constant name = "ERC20Basic";
string public constant symbol = "BSC";
uint8 public constant decimals = 18;
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
const { ethers } = require("ethers");
const sigUtil = require('@metamask/eth-sig-util');
// The wallet to sign with
const hdWallet = ethers.utils.HDNode.fromMnemonic('all all all all all all all all all all all all').derivePath(ethers.utils.defaultPath)
const privateKey = Buffer.from(hdWallet.privateKey.substr(2), 'hex')
msgParams = {
domain: {
// Defining the chain aka Rinkeby testnet or Ethereum Main Net
@alisinabh
alisinabh / build-metamask-with-typed-data.md
Last active January 17, 2022 13:38
Metamask EIP712 Trezor

Manually build metamask to claim your $LOOKS

This document will help you to build and install metamask with ability to sign typed data using trezor model T devices. (Model one does not support this yet). Please only follow this guide if you have enough technical knowledge. NEVER install anything from any other source rather than the official chrome and firefox marketplaces or metamask original website.

NOTE Do NOT install any binaries from third parties who claim they have a build version of this guide. If you want it you should build it yourself to be 100% sure that it is not tampered with. This solution is only a last resort, If you can wait a few more days I would stongly suggest to wait for an official release.

@alisinabh
alisinabh / dynamic_alias.ex
Last active June 15, 2022 18:59
Dynamically alias modules at compile time in Elixir with mox
defmodule DynamicAlias do
@moduledoc """
Helper macro to call the alias dynamically. This will allow developers to
stub the testing environment with a mock or use different modules with
different configuration without the need to use a runtime impl function.
Please note that this only works in compile time. Do not provide any runtime
specific configuration here.
"""
@alisinabh
alisinabh / bitconverter_sample.ex
Last active February 16, 2023 22:16
Elixir convert binary (byte array) to signed Int32 with pattern matching and vice versa [DEPRECARED - just use whats inside the functions]
defmodule ZigorProxy.BitConverter do
@moduledoc """
This module handles standard binary operations.
Converting binaries to and from general data types.
"""
require Logger
@doc """
Converts binary of 4 bytes into an signed integer.
@alisinabh
alisinabh / ethers_uniswap.livemd
Created January 23, 2024 18:38
Elixir Ethers and Uniswap

Uniswap ❤️ Elixir

Mix.install([
  {:ethers, "~> 0.2.2"},
  {:uniswap, github: "alisinabh/elixir_uniswap"},
  :ex_secp256k1,
  # For Images
@alisinabh
alisinabh / load_nft_data_elixir.livemd
Created February 6, 2024 05:10
Load NFT Data using Elixir Ethers

Fetch NFT Metadata

Mix.install([
  :ethers,
  :kino,
  :req
])