Skip to content

Instantly share code, notes, and snippets.

View tim-cotten's full-sized avatar

Tim Cotten tim-cotten

View GitHub Profile
@tim-cotten
tim-cotten / SampleUpdater.sol
Created November 12, 2018 03:35
SampleUpdater.sol for Talking to Ethereum Smart Contracts by Tim Cotten
pragma solidity ^0.4.0;
contract SampleUpdater {
address authorized_service_provider;
uint nonce;
function getNonce() public view returns(uint) {
return nonce;
}
@tim-cotten
tim-cotten / Infinite8BitForLoop.sol
Created November 20, 2018 03:37
Solidity: An example implementation of why not to trust `var i = 0` in for loops
//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;
@tim-cotten
tim-cotten / mysql-db-conf-example.c
Created November 28, 2018 04:18
An example of connecting to a MySQL database in C using a config text file
#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 / mysql-one-column-iterate.c
Created November 28, 2018 04:49
Iterating over a MySQL result set in C with a single column (id)
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 / index.html
Created December 5, 2018 02:34
FlippyTime Loader v1.1.0
<!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 / AbstractSingleton.php
Created December 19, 2018 16:26
An abstract singleton pattern for PHP classes
<?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 / deposit-account.sol
Last active June 13, 2019 01:49
Simple Deposit Account (Don't Use - Intro Version for Safety Discussion)
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 / deposit-account-0-1-1.sol
Last active June 13, 2019 01:50
Simple Deposit Account (v0.1.1 Don't Use - Intro Version for Safety Discussion)
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-0-1-2.sol
Last active June 13, 2019 01:50
Simple Deposit Account (v0.1.2 Don't Use - Intro Version for Safety Discussion)
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-3
Last active June 13, 2019 01:50
Simple Deposit Account (v0.1.3 Don't Use - Intro Version for Safety Discussion)
pragma solidity >=0.4.22 <0.6.0;
contract DepositAccount {
address private owner;
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
modifier withMinBalance(uint256 amount) {