Skip to content

Instantly share code, notes, and snippets.

@cameel
cameel / solidity-enums-with-data.md
Last active December 16, 2023 12:59
Enums with data in Solidity

Use cases

  • Optional/nullable data types.
  • Variant data types.
  • Flag with extra information needed only in some cases (or different in different cases).
  • Modeling states in a state machine where each state can have some data associated with it.
  • List of operations for batch processing, where each operation can have its own arguments.
  • Alternative to function overloading that allows avoiding combinatorial explosion when there are multiple parameters that need variants.
  • Nested data structures with heterogenous nodes.

Syntax and semantics

// Builders
class SimpleBuilder {
constructor(private current = {}) {
}
prop(key: string, value: any) {
return new SimpleBuilder({ ...this.current, ...{ [key]: value } });
}
@bprosnitz
bprosnitz / cloneobjectstring.js
Last active March 10, 2016 06:52
Generate javascript code that will create a clone of a given javascript object
function buildValMap(obj, m) {
if (typeof obj !== 'object' || obj === null) {
return '';
}
if (obj === Object.prototype || obj === Array.prototype) {
return '';
}
if (m.has(obj)) {
return '';
}
@maxlinc
maxlinc / android_lexer.rb
Created May 8, 2014 04:48
Workaround for java vs android in slate
require 'rouge'
module Rouge
module Lexers
class Android < Rouge::Lexers::Java
tag 'android'
end
end
end
@kagemusha
kagemusha / gist:5866759
Created June 26, 2013 11:37
Using Debugger with Grunt
version: grunt-cli v0.1.8
1. Install node-inspector globally (-g)
npm install -g node-inspector
2. Add debugger statements to your code
3. Run your grunt task in debug mode
@justincampbell
justincampbell / after.sh
Created March 1, 2013 17:45
Jenkins + GitHub Commit Status API
if [[ $BUILD_STATUS == "success" ]]
then
export STATUS="success"
else
export STATUS="failure"
fi
curl "https://api.github.com/repos/justincampbell/my_repo/statuses/$GIT_COMMIT?access_token=abc123" \
-H "Content-Type: application/json" \
-X POST \
@tlberglund
tlberglund / git-loglive
Last active January 12, 2024 03:40
Log Live Git Command
#!/bin/bash
while :
do
clear
git --no-pager log --graph --pretty=oneline --abbrev-commit --decorate --all $*
sleep 1
done
@msridhar
msridhar / imdb_season_ratings.js
Created February 25, 2012 23:29
Compute Average IMDB Rating for TV Show Season using node.js
var jsdom = require('jsdom');
var re = /(\d+)\.(\d+)/;
jsdom.env({
// IMDB show URL + '/eprate' (Simpsons URL below)
html: 'http://www.imdb.com/title/tt0096697/eprate',
scripts: ['http://code.jquery.com/jquery-1.7.1.min.js'],
done: function (errors, window) {
var $ = window.$;