Skip to content

Instantly share code, notes, and snippets.

View passandscore's full-sized avatar

Jason Schwarz passandscore

View GitHub Profile
@passandscore
passandscore / DeleteNumberAtIndex.sol
Created June 21, 2024 13:23
Solidity Challenge - DeleteNumberAtIndex
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract DeleteNumberAtIndexChallenge {
struct Number {
uint value;
}
Number[] public numbers;
@passandscore
passandscore / Reentrancy.sol
Created June 19, 2024 20:00
Educational Solidity Example: Demonstrating a Reentrancy Attack
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
// Inspired By: https://solidity-by-example.org/hacks/re-entrancy/
/**
* @title EtherStore
* @dev A simple contract for depositing and withdrawing ETH.
* Vulnerable to re-entrancy attack.
*/
@passandscore
passandscore / TokenLockers.sol
Created February 12, 2024 21:25
Manages the timelock logic for external tokens.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "./ERC20.sol";
import "./interfaces/IERC20.sol";
contract TokenLockers is ERC20 {
error InsufficentFunds();
error InsufficentInputValue();
error InvalidLocktime();
@passandscore
passandscore / htmlForm.js
Created May 6, 2021 19:07
Basic HTML Form
<form>
<h3>FORM</h3>
<label>TITLE</label>
<input type="title" id="title" placeholder="Title...">
<label>AUTHOR</label>
<input type="title" id="author" placeholder="Author...">
<label>ISBN</label>
<input type="title" id="isbn" placeholder="Isnb...">
<button>Submit</button>
</form>
function get(url) {
// Return a new promise.
return new Promise(function(resolve, reject) {
// Do the usual XHR stuff
var req = new XMLHttpRequest();
req.open('GET', url);
req.onload = function() {
// This is called even on 404 etc
// so check the status
@passandscore
passandscore / kinvey.js
Last active May 5, 2021 16:33
Kinvey DB request library
//How to use it in a JS file
document.addEventListener('DOMContentLoaded', main)
const kinvey = new Kinvey('kid_BkYBymjvd', 'ed0eed3599fa4d5d9d062fae8755f43c');
const data = {
username: 'guest',
password: 'guest'
}
@passandscore
passandscore / httpClient.js
Created May 5, 2021 16:28
httpClient - DB fetch library
class httpClient {
// Get Request
get(url) {
return new Promise((resolve, reject) => {
fetch(url)
.then((res) => {
if (res.ok) {
return res.json();
}
}).then(data => resolve(data))
@passandscore
passandscore / arrayToLinkedList.js
Created April 26, 2021 19:38
Convert an Array to a Linked List
function linkedList(arr) {
return arr.reduceRight((next, value) => ({ value, next }), null);
}
let l = [3, 1, 2, 3, 4, 5];
console.log(linkedList(l));
@passandscore
passandscore / linkedLists.js
Last active April 27, 2021 17:37
DataStructure - Linked List Principles
//Algorithms - Linked List Principles
//Language: JavaScript
class Node {
constructor(data, next = null) {
this.data = data;
this.next = next;
}
}
@passandscore
passandscore / unit-testing.js
Created April 25, 2021 01:26
Unit Testing Template (Mocha & Chai)
//Unit testing template
//Language: JavaScript
//Packages: Mocha, Chai
//Javascript file
module.exports = subSum;
//JavaScript test file