Skip to content

Instantly share code, notes, and snippets.

@GNSPS
GNSPS / ProxyFactory.sol
Last active October 9, 2021 08:47
Improved `delegatecall` proxy contract factory (Solidity) [v0.0.5]
/***
* Shoutouts:
*
* Bytecode origin https://www.reddit.com/r/ethereum/comments/6ic49q/any_assembly_programmers_willing_to_write_a/dj5ceuw/
* Modified version of Vitalik's https://www.reddit.com/r/ethereum/comments/6c1jui/delegatecall_forwarders_how_to_save_5098_on/
* Credits to Jorge Izquierdo (@izqui) for coming up with this design here: https://gist.github.com/izqui/7f904443e6d19c1ab52ec7f5ad46b3a8
* Credits to Stefan George (@Georgi87) for inspiration for many of the improvements from Gnosis Safe: https://github.com/gnosis/gnosis-safe-contracts
*
* This version has many improvements over the original @izqui's library like using REVERT instead of THROWing on failed calls.
* It also implements the awesome design pattern for initializing code as seen in Gnosis Safe Factory: https://github.com/gnosis/gnosis-safe-contracts/blob/master/contracts/ProxyFactory.sol
@maurelian
maurelian / -
Created January 16, 2018 14:25
function controlSelf() {
eval "defaults write org.eyebeam.SelfControl BlockDuration -int $1"
extras=""
if [ "$2" = "nuke" ]; then
extras="inbox.google.com slack.com"
fi
blacklist="facebook.com news.ycombinator.com reddit.com twitter.com $extras"
eval "defaults write org.eyebeam.SelfControl HostBlacklist -array $blacklist"
defaults read org.eyebeam.SelfControl
sudo /Applications/SelfControl.app/Contents/MacOS/org.eyebeam.SelfControl $(id -u $(whoami)) --install > /dev/null 2>&1
@alexvandesande
alexvandesande / ethernalsale.js
Last active October 21, 2021 04:40
This is a first draft at what could be a continuous token sale. I just wrote it and haven't tested it but it shows the proof of concept: tokens are continuously generated in any curve desired and sold for the highest bidder. Since there's a maximum token sale speed, this guarantees that sales can't end too quickly. Since the sale always starts f…
pragma solidity ^0.4.2;
contract ethernalSale {
struct order {
uint amount;
address buyer;
}
mapping (uint => order) orderBook;
mapping (address => uint) balanceOf;
/*
* STATICCALL Proxy
*
* It expects the input:
* 256 bit - address
* 256 bit - gas
* 256 bit - value
* n bit - calldata to be proxied
*
* And returns the output:
@VictorTaelin
VictorTaelin / ethereum_delayed_computations.md
Last active April 12, 2018 16:42
Make Ethereum massively scalable today with delayed computations

Make Ethereum massively scalable today with delayed computations

Suppose you're writing a contract which involves a huge amount of participants. As an example, think of an online, blockchain-based Trading-Card Game with tournaments. How would you program a playCard function? You might be thinking of something like this:

function playCard(uint player, uint card){
    ...
    else if (card == PROFESSOR_OAK){
        // shuffles the player's hand on his deck
 shuffleHand(player)
/**
* Base contract that all upgradeable contracts should use.
*
* Contracts implementing this interface are all called using delegatecall from
* a dispatcher. As a result, the _sizes and _dest variables are shared with the
* dispatcher contract, which allows the called contract to update these at will.
*
* _sizes is a map of function signatures to return value sizes. Due to EVM
* limitations, these need to be populated by the target contract, so the
* dispatcher knows how many bytes of data to return from called functions.
anonymous
anonymous / FCXI.ino
Created May 4, 2016 05:41
/*
Go ahead and use this for whatever you want. Credit would be nice, but I can't stop you and if this helps you in any way, I'm cool with it. Besides, I didn't even write a few chunks of this.
Author: Zweiter
Version: 1.1
*/
@nicklockwood
nicklockwood / gist:21495c2015fd2dda56cf
Last active August 13, 2020 13:57
Thoughts on Swift 2 Errors

Thoughts on Swift 2 Errors

When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.

So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.

Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?

I'm going to cover three things in this post:

@kristopherjohnson
kristopherjohnson / enumerateEnum.swift
Last active May 12, 2017 01:56
Helper functions for enumerating values of a Swift enum
// Protocol for a type that supports a fromRaw(Int) conversion
// (such as "enum Foo: Int { ... }")
protocol ConvertibleFromRawInt {
class func fromRaw(raw: Int) -> Self?
}
// Note: Tried to use Swift's standard RawRepresentable protocol rather
// than ConvertibleFromRawInt, but couldn't get it to compile.
// Don't know whether it is a Swift bug or something I was doing wrong.
@tleen
tleen / gist:5109955
Created March 7, 2013 17:30
Format a Javascript Date to RFC-822 datetime using moment.js
var rfc822Date = moment(yourDate).format('ddd, DD MMM YYYY HH:mm:ss ZZ')