Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am eddmann on github.
  • I am eddmann (https://keybase.io/eddmann) on keybase.
  • I have a public key ASCtR4CJdl_FFsytpfmf0RRuxlyRrgP8lXazqBwXWkuQfAo

To claim this, I am signing this object:

@eddmann
eddmann / bitcoin-merkle-proofs.js
Created November 10, 2017 10:20
Bitcoin Internals: Verifying Merkle Roots using Merkle Proofs in JavaScript
const fetchLatestBlock = () =>
fetch(`https://blockchain.info/q/latesthash?cors=true`)
.then(r => r.text());
const fetchMerkleRootAndTransactions = block =>
fetch(`https://blockchain.info/rawblock/${block}?cors=true`)
.then(r => r.json())
.then(d => [d.mrkl_root, d.tx.map(t => t.hash)]);
const random = arr =>
@eddmann
eddmann / bitcoin-merkle-tree.js
Last active July 24, 2023 13:55
Bitcoin Internals: How Blocks use Merkle Trees in JavaScript
const fetchLatestBlock = () =>
fetch(`https://blockchain.info/q/latesthash?cors=true`)
.then(r => r.text());
const fetchMerkleRootAndTransactions = block =>
fetch(`https://blockchain.info/rawblock/${block}?cors=true`)
.then(r => r.json())
.then(d => [d.mrkl_root, d.tx.map(t => t.hash)]);
const toBytes = hex =>
@eddmann
eddmann / handler.js
Created November 7, 2017 13:32
Scheduled Start/Stop of EC2 Instances using Lambda and Serverless (Extra)
'use strict';
const AWS = require('aws-sdk');
module.exports.stateChange = (event, context, callback) => {
const { state, id, region } = event;
const ec2 = new AWS.EC2({ region });
ec2[`${state}Instances`]({ InstanceIds: [id] }).promise()
@eddmann
eddmann / handler.js
Created November 6, 2017 13:34
Scheduled Start/Stop of EC2 Instances using Lambda and Serverless
'use strict';
const AWS = require('aws-sdk');
module.exports.start = (event, context, callback) => {
const ec2 = new AWS.EC2({ region: event.region });
ec2.startInstances({ InstanceIds: [event.id] }).promise()
.then(() => callback(null, `Successfully started ${event.id}`))
.catch(err => callback(err));
@eddmann
eddmann / modify-ec2-instance-type.js
Created November 3, 2017 15:32
Scheduled EC2 Instance Type Modification using Lambda and CloudWatch Events
// Demonstration video can be found at: https://youtu.be/_gJyK1-NGq8
// ModifyEC2InstanceType
const AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
const { instanceId, instanceRegion, instanceType } = event;
const ec2 = new AWS.EC2({ region: instanceRegion });
@eddmann
eddmann / start-stop-ec2-instances.js
Created November 3, 2017 14:00
Scheduled Start/Stop of EC2 Instances using Lambda and CloudWatch Events
// Demonstration video can be found at: https://youtu.be/roAerKVfq-Y
// StopEC2Instance
const AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
const ec2 = new AWS.EC2({ region: event.instanceRegion });
ec2.stopInstances({ InstanceIds: [event.instanceId] }).promise()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
"use strict";
@eddmann
eddmann / SecureSessionHandler.php
Created April 9, 2014 12:18
Secure session handler implementation.
<?php
class SecureSessionHandler extends SessionHandler {
protected $key, $name, $cookie;
public function __construct($key, $name = 'MY_SESSION', $cookie = [])
{
$this->key = $key;
$this->name = $name;
@eddmann
eddmann / oop.js
Last active April 28, 2016 08:38
OOP in JavaScript
// Prototypical Model
var UserPrototype = {};
UserPrototype.constructor = function(name)
{
this._name = name;
};
UserPrototype.getName = function()
{
return this._name;