Skip to content

Instantly share code, notes, and snippets.

@noman-land
noman-land / BattleHash.sol
Last active April 21, 2018 20:58
Board is 2x2 for testing purposes, it will be 10x10 eventually.
pragma experimental ABIEncoderV2;
pragma solidity ^0.4.23;
contract BattleHash {
uint256 public numGames;
modifier validShot(uint256 gameId) {
Game storage game = games[gameId];
address lastShooter = getLastShooter(game);
@noman-land
noman-land / GCDLCMCache.sol
Created April 19, 2018 16:53 — forked from 3esmit/GCDLCMCache.sol
hacky gcd lcm solidity with cache
pragma solidity ^0.4.21;
contract GCDLCMCache {
mapping (bytes32 => uint256) public cache;
enum CacheType { GCD, LCM }
function gcd(uint256[] input)
@noman-land
noman-land / paillier.js
Last active April 18, 2018 06:48
Example of additive and multiplicative homomorphic encryption
// Reference: https://radicalrafi.github.io/posts/homomorphic-encryption/
// npm i --save big-integer
const bigInt = require('big-integer');
const L = (x, n) => x.minus(1).divide(n);
function createEncryptor({ n, g }) {
return (m, r) => g.pow(m).times(r.pow(n)).mod(n.pow(2));
}
@noman-land
noman-land / LinkedList.sol
Created April 4, 2018 06:49
Push and pop to the end
pragma solidity ^0.4.21;
contract LinkedList {
bool public isEmpty = true;
uint public length = 0;
bytes32 public head;
bytes32 public tail;
struct LinkNode {
string value;
@noman-land
noman-land / MultiplayerGame.sol
Last active April 1, 2018 22:54
Generic mutiplayer game contract for complex games to inherit from.
pragma solidity ^0.4.21;
contract MultiplayerGame {
uint[3] public SEMVER = [0, 1, 0];
uint public numGames;
enum ListType {
None,
Whitelist,
Blacklist
pragma solidity ^0.4.10;
contract ReLike {
function ReLike() {
}
enum Rating {
UNRATED,
LIKE,
DISLIKE
pragma solidity ^0.4.11;
contract Wiki {
function Wiki() {
}
struct Diff {
address owner;
uint currentSwarmHash;
pragma solidity ^0.4.11;
contract DMail {
address owner;
function DMail() public {
owner = msg.sender;
}
struct Message {
pragma solidity ^0.4.11;
contract AnsweringMachine {
enum Status {
Here,
Busy,
Away
}
struct AwayStatus {
pragma solidity ^0.4.11;
contract Interviewer {
address public answerer;
address public asker;
function Interviewer(address _asker, address _answerer) {
asker = _asker;
answerer = _answerer;
}