Skip to content

Instantly share code, notes, and snippets.

@kdelwat
kdelwat / Key value storage - first draft
Created June 23, 2021 11:28
Example smart contracts from the Women in Digital workshop. Adapted from the examples at https://docs.soliditylang.org/en/v0.8.6/solidity-by-example.html
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract KV {
bytes32[] private reservedKeys;
mapping(bytes32 => string) private values;
constructor(bytes32[] memory _reservedKeys) {
reservedKeys = _reservedKeys;
}
@kdelwat
kdelwat / deprog.py
Created February 12, 2021 20:52
Replace progressive JPEGs in album art with non-progressive JPEGs, recursively
import eyed3
import io
import os
from PIL import Image
def is_progressive(img):
return "progression" in img.info or "progressive" in img.info
def deprogressify(filename):
/**
* Use this file to configure your truffle project. It's seeded with some
* common settings for different networks and features like migrations,
* compilation and testing. Uncomment the ones you need or modify
* them to suit your project as necessary.
*
* More information about configuration can be found at:
*
* truffleframework.com/docs/advanced/configuration
*
#!/usr/bin/env bash
# Based on https://medium.com/@chim/ethereum-how-to-setup-a-local-test-node-with-initial-ether-balance-using-geth-974511ce712
# Initialise a local geth testnet with automine
CHAIN_DIRECTORY=~/.testnet;
STARTING_BALANCE="0x5337000000000000000000"
if [ -d "$CHAIN_DIRECTORY" ]; then
rm -r ${CHAIN_DIRECTORY}
// Given an array of visited vertices, where each element represents the parent of the vertex,
// fill the path array with the route between src and dest.
int reconstructShortestPath(Vertex src, Vertex dest, int *visited, int nV, int *path) {
// Based on the suggestion here: https://stackoverflow.com/questions/8379785/how-does-a-breadth-first-search-work-when-looking-for-shortest-path#comment27820665_8379892
// Record the route in a queue.
Queue route = newQueue();
// Backtrack through the visited array, recording each vertex in the queue.
int current = dest;
import Web3 from "web3";
import { getWeb3 } from "./utils/web3";
const Contract = require("truffle-contract");
import * as SaleABI from "../../build/contracts/YabbySale.json";
import * as CoinABI from "../../build/contracts/YabbyCoin.json";
function showWeb3(divName: string, web3: Web3) {
const elt = document.getElementById(divName);
#! /bin/bash
make
./vmsim lru 5 4 < trace1 > my-out-lru-5-4-trace1.txt
diff my-out-lru-5-4-trace1.txt out-lru-5-4-trace1.txt
./vmsim fifo 5 4 < trace1 > my-out-fifo-5-4-trace1.txt
diff my-out-fifo-5-4-trace1.txt out-fifo-5-4-trace1.txt
./vmsim lru 8 4 < trace2 > my-out-lru-8-4-trace2.txt
@kdelwat
kdelwat / List.c
Created October 10, 2017 21:09
COMP1511 list example
#include <stdio.h>
#include <stdlib.h>
#include "List.h"
List makeList(void) {
List l = calloc(1, sizeof(list));
return l;
}
List addAtHead(List l, int value) {
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node *next;
};
struct node *new_node(int data, struct node *next);
void print_list(struct node *head);
@kdelwat
kdelwat / controls.js
Created July 13, 2017 23:10
Touch controls for Code Camp World
var mouseDeadZone = 50;
if (this.game.getMouseX() > this.getXPosition() + mouseDeadZone)
{
this.setXSpeed(100);
this.setYSpeed(0);
this.playAnimation('Right');
}
else if (this.game.getMouseX() < this.getXPosition() - mouseDeadZone)
{
this.setXSpeed(-100);