Skip to content

Instantly share code, notes, and snippets.

View zabirauf's full-sized avatar
👨‍💻
I may be slow to respond.

Zohaib Rauf zabirauf

👨‍💻
I may be slow to respond.
View GitHub Profile
@zabirauf
zabirauf / curry.ts
Created January 3, 2019 04:53
Strongly typed currying in Typescript
type Func = (...args: any[]) => any;
type FirstParam<T extends Func> =
T extends (arg: infer J, ...args: infer U) => infer V
? J
: never;
type TailParams<T extends Func> =
T extends (arg: infer J, ...args: infer U) => infer V
? U
pragma solidity ^0.4.21;
import './GlobalCalculator.sol';
contract GlobalCalculator_V2 is GlobalCalculator_V1 {
function getMul() public view returns (uint mul) {
mul = 1;
for (uint i = 0;i < _nums.length; i++) {
mul *= _nums[i];
pragma solidity ^0.4.21;
contract GlobalCalculator_V1 {
uint[] internal _nums;
function addNum(uint x) public {
_nums.push(x);
}
function getSum() public view returns (uint sum) {
@zabirauf
zabirauf / UpgradeableContractProxy.sol
Last active April 16, 2018 01:00
Example of a ethereum smart contract that can be upgraded
pragma solidity ^0.4.21;
import "./Ownable.sol";
contract UpgradeableContractProxy is Ownable {
address private _currentImplementation;
function UpgradeableContractProxy() public Ownable() {
}
pragma solidity ^0.4.15;
import "truffle/Assert.sol";
import { StringToUintMap } from "../libraries/StringToUintMap.sol";
contract TestStringToUintMap {
StringToUintMap.Data private _stringToUintMapData;
function testInsertNewKey() {
// Arrange
module.exports = {
networks: {
development: {
host: "localhost", // Ganache RPC server URL
port: 7545, // Ganache RPC server Port
network_id: "*" // Match any network id
}
}
};
const StringToUintMap = artifacts.require("./StringToUintMap.sol");
const PersonsAge = artifacts.require("./PersonsAge.sol");
module.exports = function(deployer) {
deployer.deploy(StringToUintMap);
deployer.link(StringToUintMap, PersonsAge);
deployer.deploy(PersonsAge);
};
// Code for PersonsAge.sol
pragma solidity ^0.4.15;
import { StringToUintMap } from "../libraries/StringToUintMap.sol";
contract PersonsAge {
StringToUintMap.Data private _stringToUintMapData;
// Code for StringToUintMap.sol
pragma solidity ^0.4.15;
library StringToUintMap {
struct Data {
mapping (string => uint8) map;
}
function insert(

Keybase proof

I hereby claim:

  • I am zabirauf on github.
  • I am zabirauf (https://keybase.io/zabirauf) on keybase.
  • I have a public key ASARuUOjzzy29X8HMZTWPwaznADwtY2m8LXL_HshE-64-Ao

To claim this, I am signing this object: