Skip to content

Instantly share code, notes, and snippets.

View jamiebullock's full-sized avatar

Jamie Bullock jamiebullock

View GitHub Profile
@jamiebullock
jamiebullock / adder.rs
Created February 3, 2022 17:41
Elrond Adder
#![no_std]
elrond_wasm::imports!();
/// One of the simplest smart contracts possible,
/// it holds a single variable in storage, which anyone can increment.
#[elrond_wasm::derive::contract]
pub trait Adder {
#[view(getSum)]
#[storage_mapper("sum")]
@jamiebullock
jamiebullock / .zshrc
Created April 9, 2021 10:06
Manjaro zshrc adapted for Mac
## Options section
setopt correct # Auto correct mistakes
setopt extendedglob # Extended globbing. Allows using regular expressions with *
setopt nocaseglob # Case insensitive globbing
setopt rcexpandparam # Array expension with parameters
setopt nocheckjobs # Don't warn about running processes when exiting
setopt numericglobsort # Sort filenames numerically when it makes sense
setopt nobeep # No beep
setopt appendhistory # Immediately append history instead of overwriting
@jamiebullock
jamiebullock / print_balance_dry.rb
Created January 31, 2021 12:21
print_balance DRY version (credit: Pragmatic Programmer)
def format_amount(value)
result = sprintf("%10.2f", value.abs)
if value < 0
result + "-"
else
result + " "
end
end
def print_line(label, value)
def print_balance(account)
printf "Debits: %10.2f\n", account.debits
printf "Credits: %10.2f\n", account.credits
if account.fees < 0
printf "Fees: %10.2f-\n", -account.fees
else
printf "Fees: %10.2f\n", account.fees
end
printf " ———-\n"
if account.balance < 0
@jamiebullock
jamiebullock / try_catch.js
Created September 4, 2020 08:14
Dubious Try / Catch
var item;
try
{
item = previousItem;
}
catch (ReferenceError)
{
item = new Item();
previousItem = item;
@jamiebullock
jamiebullock / dynamic_dispatch.js
Last active September 4, 2020 07:58
Dynamic dispatch
const handleShape = (shape) => { console.log(shape.area()); }
class Shape
{
constructor(width = 2)
{
this.width = width;
}
area()
{
@jamiebullock
jamiebullock / colour_jump.js
Last active September 12, 2020 18:13
Colour Jump Table
const stop = () => { console.log("stop called"); }
const go = () => { console.log("go called"); }
const colour = 'red';
const handleColour =
{
'red' : stop,
'amber' : stop,
'green' : go,
@jamiebullock
jamiebullock / colour_switch.js
Created September 3, 2020 17:18
Colour Switch
switch (colour)
{
case 'red':
case 'amber':
stop();
break;
case 'green':
case 'flashing amber':
go();
break;
@jamiebullock
jamiebullock / switch_statement.js
Created September 3, 2020 17:16
Switch statement
switch (expression)
{
case value1:
// code executed if expression matches value1
[break;]
case value2:
// code executed if expression matches value2
[break;]
...
case valueN:
{
"Fruit":
[
{
"Name": "Banana",
"Colour": "Yellow"
},
{
"Name": "Apple",
"Colour": "Green"