Skip to content

Instantly share code, notes, and snippets.

Tim Cotten tim-cotten

Block or report user

Report or block tim-cotten

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tim-cotten
tim-cotten / deposit-account-1-0-0.sol
Last active Jun 13, 2019
Simple Deposit Account (v1.0.0)
View deposit-account-1-0-0.sol
pragma solidity >=0.4.22 <0.6.0;
/**
* @title DepositAccount - simple contract that stores ether and allows full or
* partial withdrawals by the account owner.
* @author Tim Cotten <tim@cotten.io>
*/
contract DepositAccount {
address private owner;
@tim-cotten
tim-cotten / deposit-account-0-1-3
Last active Jun 13, 2019
Simple Deposit Account (v0.1.3 Don't Use - Intro Version for Safety Discussion)
View deposit-account-0-1-3
pragma solidity >=0.4.22 <0.6.0;
contract DepositAccount {
address private owner;
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
modifier withMinBalance(uint256 amount) {
@tim-cotten
tim-cotten / deposit-account-0-1-2.sol
Last active Jun 13, 2019
Simple Deposit Account (v0.1.2 Don't Use - Intro Version for Safety Discussion)
View deposit-account-0-1-2.sol
pragma solidity >=0.4.22 <0.6.0;
contract DepositAccount {
address owner;
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
modifier hasBalance(uint256 amount) {
@tim-cotten
tim-cotten / deposit-account-0-1-1.sol
Last active Jun 13, 2019
Simple Deposit Account (v0.1.1 Don't Use - Intro Version for Safety Discussion)
View deposit-account-0-1-1.sol
pragma solidity >=0.4.22 <0.6.0;
contract DepositAccount {
address owner;
constructor() public {
owner = msg.sender;
}
function withdraw() public {
require(owner == msg.sender);
@tim-cotten
tim-cotten / deposit-account.sol
Last active Jun 13, 2019
Simple Deposit Account (Don't Use - Intro Version for Safety Discussion)
View deposit-account.sol
pragma solidity >=0.4.22 <0.6.0;
contract DepositAccount {
address payable owner;
constructor() public {
owner = msg.sender;
}
function withdraw() public {
require(owner == msg.sender);
@tim-cotten
tim-cotten / AbstractSingleton.php
Created Dec 19, 2018
An abstract singleton pattern for PHP classes
View AbstractSingleton.php
<?php
/**
* Allows a given child class to behave as a Singleton without interfering
* with other child classes also using the Singleton behavior.
*
* @author Tim Cotten <tim@cotten.io>
*
* @abstract
*/
abstract class AbstractSingleton
@tim-cotten
tim-cotten / index.html
Created Dec 5, 2018
FlippyTime Loader v1.1.0
View index.html
<!DOCTYPE html>
<html class="no-js" lang="en">
<!--
FlippyTime™
Version: 1.1.0
Copyright © 2017 Tim Cotten
Sound design by SoundJay.com (https://www.soundjay.com/)
-->
@tim-cotten
tim-cotten / mysql-one-column-iterate.c
Created Nov 28, 2018
Iterating over a MySQL result set in C with a single column (id)
View mysql-one-column-iterate.c
do {
MYSQL_FIELD *fields;
MYSQL_BIND *rs_bind;
if (mysql_stmt_field_count(stmt) > 0) {
MYSQL_RES *rs_metadata = mysql_stmt_result_metadata(stmt);
fields = mysql_fetch_fields(rs_metadata);
rs_bind = (MYSQL_BIND *) malloc(sizeof (MYSQL_BIND));
memset(rs_bind, 0, sizeof (MYSQL_BIND));
@tim-cotten
tim-cotten / mysql-db-conf-example.c
Created Nov 28, 2018
An example of connecting to a MySQL database in C using a config text file
View mysql-db-conf-example.c
#include <mysql.h>
#include <my_global.h>
// Note: TRUE and FALSE will always be defined by the MySQL headers
#define MYSQL_CONF_NUM 4
#define MYSQL_CONF_HOSTNAME 0
#define MYSQL_CONF_DATABASE 1
#define MYSQL_CONF_USERNAME 2
#define MYSQL_CONF_PASSWORD 3
@tim-cotten
tim-cotten / Infinite8BitForLoop.sol
Created Nov 20, 2018
Solidity: An example implementation of why not to trust `var i = 0` in for loops
View Infinite8BitForLoop.sol
//sol Infinite8BitForLoop
// @authors
// Tim Cotten <tim@cotten.io> (https://blog.cotten.io)
// An example implementation of why not to trust `var i = 0` in for loops
// Input to the test function above 255 results in an infinite loop
pragma solidity ^0.4.0;
contract Infinite8BitForLoop {
function test(uint256 x) public pure returns(uint256)
{
uint256 total = 0;
You can’t perform that action at this time.