Skip to content

Instantly share code, notes, and snippets.

View AllanJunLi's full-sized avatar
💭
Learning web3 / blockchain.

Allan JL AllanJunLi

💭
Learning web3 / blockchain.
  • 21 Hash
  • Sydney
  • 17:29 (UTC +10:00)
View GitHub Profile
@AllanJunLi
AllanJunLi / StorageFactory.sol
Created June 15, 2023 03:11
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=soljson-v0.8.18+commit.87f61d96.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import { SimpleStorage } from "./SimpleStorage.sol";
contract StorageFactory {
SimpleStorage[] public listOfSimpleStorageContracts;
function createSimpleStorageContract() public {
listOfSimpleStorageContracts.push(new SimpleStorage());
@AllanJunLi
AllanJunLi / SimpleStorage.sol
Created June 14, 2023 06:56
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=soljson-v0.8.18+commit.87f61d96.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
contract SimpleStorage {
// Basic Types: boolean, unit, int, address, bytes
// bool hasFavoriteNumber = true;
// uint256 favoriteNumber = 88;
// string favoriteNumberInText = "eighty-eight";
// int256 favoriteInt = -88;
// address myAddress = 0x687Ff6d6a2D149f6475b83BaEC087067b62BE9E8;
@AllanJunLi
AllanJunLi / BlockChain.java
Last active November 6, 2018 05:50
Java implementation of blockchain concept
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import java.util.List;
public class BlockChain {
@AllanJunLi
AllanJunLi / RegexTest.java
Created June 1, 2018 07:13
Learning Java regular expression
public class RegexTestStrings {
public static final String TEST = "This is my small example string which I'm going to use for pattern matching.";
public static void main(String[] args) {
System.out.println(TEST.matches("\\w.*"));
// split by whitespace
String[] splitStr = TEST.split("\\s+");
System.out.println(splitStr.length);
for (String str : splitStr) {
System.out.println(str);
@AllanJunLi
AllanJunLi / constructor.js
Created August 16, 2015 13:17
JavaScript class constructor
function Circle(radius) {
this.radius = radius;
this.area = function() {
return this.radius * this.radius * Math.PI;
};
}
var instance = {};
Circle.call(instance, 5);
instance.area();
@AllanJunLi
AllanJunLi / greeter.js
Last active August 29, 2015 14:27
JS function closure
function greeter(saluatation) {
var counter = 0; // If in java counter needs to be defined as final
var prefix = '. ' + saluatation + ' ';
return function (name) { // is bound to counter and prefix, (we call the variables that we are bound to closure)
counter++; // same reference to the outter counter, therefore keeps state
return counter + prefix + name + '!';
};
}
var greet = greeter('Hello');