Skip to content

Instantly share code, notes, and snippets.

@barrasso
barrasso / SimpleStorage.sol
Created July 13, 2017 14:12
Simple Storage Test Solidity Contract
pragma solidity 0.4.13;
contract SimpleStore {
uint storedData;
event DataStored(uint data);
function set(uint x) {
storedData = x;
DataStored(storedData);
@barrasso
barrasso / IC3Token.sol
Created July 13, 2017 21:07
My First ERC20 Token Contract
pragma solidity ^0.4.8;
contract IC3Token {
string public constant symbol = "IC3";
string public constant name = "IC3 2017 Bootcamp Token";
uint8 public constant decimals = 18;
uint256 _totalSupply;
// balances for each account
mapping(address => uint256) balances;
@barrasso
barrasso / vulnerable.sol
Last active July 14, 2017 18:33
Vulnerable ERC20 Token
pragma solidity^0.4.0;
contract TestToken {
string constant name = "IC3 2017 Bootcamp Token";
string constant symbol = "IC3";
uint8 constant decimals = 18;
uint total;
struct Allowed {
mapping (address => uint256) _allowed;
@barrasso
barrasso / hackzors.sol
Created July 14, 2017 22:08
Sample Re-Entrancy Exploit
pragma solidity^0.4.0;
contract Hackzor {
address public contract_address;
// constructor
function Target(address _addr) {
contract_address = _addr;
}
@barrasso
barrasso / Conference.sol
Created July 15, 2017 19:10
Contract to buy tickets to a conference in Solidity
contract Conference {
address public organizer;
mapping (address => uint) public registrantsPaid;
uint public numRegistrants;
uint public quota;
// so you can log these events
event Deposit(address _from, uint _amount);
event Refund(address _to, uint _amount);
function Conference() { // Constructor
organizer = msg.sender;
@barrasso
barrasso / ShortAddrToken.sol
Created July 16, 2017 15:33
Vulnerable ERC20 Token by shorting address
pragma solidity^0.4.11;
library SafeMath {
function mul(uint a, uint b) internal returns (uint) {
uint c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint a, uint b) internal returns (uint) {
@barrasso
barrasso / Crowdsale.sol
Created July 16, 2017 16:51
ERC20 Token crowdsale in Solidity
pragma solidity ^0.4.8;
contract token { function transfer(address receiver, uint amount){ } }
contract Crowdsale {
address public beneficiary;
uint public fundingGoal; uint public amountRaised; uint public deadline; uint public price;
token public tokenReward;
mapping(address => uint256) public balanceOf;
bool fundingGoalReached = false;
event GoalReached(address beneficiary, uint amountRaised);
@barrasso
barrasso / Migrations.sol
Created August 15, 2017 23:17
used to store the latest contract you have deployed to the blockchain
pragma solidity ^0.4.2;
contract Migrations {
address public owner;
uint public last_completed_migration;
modifier restricted() {
if (msg.sender == owner) _;
}
@barrasso
barrasso / UIColor+Extension.swift
Created October 3, 2017 02:13
Extends UIColor to get color from hex code
import UIKit
public extension UIColor {
static func colorFromHex(rgbValue:UInt32, alpha:Double=1.0)->UIColor {
let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0
let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0
let blue = CGFloat(rgbValue & 0xFF)/256.0
return UIColor(red:red, green:green, blue:blue, alpha:CGFloat(alpha))
}
}
@barrasso
barrasso / Plist.swift
Created October 3, 2017 02:29
Plist handler in Swift 4.0
import UIKit
class Plist {
enum PlistError: Error {
case FileNotWritten
case FileDoesNotExist
}
private let name: String