Skip to content

Instantly share code, notes, and snippets.

View coopermaruyama's full-sized avatar

Cooper Maruyama coopermaruyama

View GitHub Profile
@coopermaruyama
coopermaruyama / solution.js
Created December 28, 2023 13:49
decodeway
const map = 'abcdefghijklmnopqrstuvwxyz'
.split('')
.reduce((obj, curr, i) => ({
...obj,
[String(i+1)]: curr.toUpperCase()
}), {})
/**
* @param {string} s
* @return {number}
@coopermaruyama
coopermaruyama / geth-nginx-healthcheck.md
Last active January 16, 2024 02:51
Go-Ethereum (Geth) NGINX Health Check (Ubuntu)

Uses NGINX's njs module to query geth's eth_syncing RPC endpoint. Considered as "healthy" only when the syncing attribute is false.

This is useful if you are managing a cluster of geth nodes behind a load balancer and need a compatible healthcheck.

  1. Create a directory to store our njs script
@coopermaruyama
coopermaruyama / nest.js
Last active May 25, 2020 23:59
Nest Thermostat: Win the temperature wars
// Sick of another person always changing the temperature?
// This will set your desired temperature every few seconds :)
// 1. Go to https://home.nest.com
// 2. Login
// 3. Pull up thermostat page
// 4. Open console (cmd + alt + J)
// 5. Paste this in, set wantTemp to whatever you want
function setTemp(want) {
@coopermaruyama
coopermaruyama / generate-signed-order.ts
Created January 6, 2020 20:13
Create a signed order using 0x
//
// Generate a signed ZRX order
//
// Requires ts-node and tsconfig-paths to be installed
//
// USAGE EXAMPLE (Sell 5 orchid for 1 ETH):
//
// ERC20_ADDRESS=0x4575f41308EC1483f3d399aa9a2826d74Da13Deb \
// SELL_AMOUNT=5 \
// SELL_FOR_ETH_AMOUNT=1 \
@coopermaruyama
coopermaruyama / index.ts
Last active December 17, 2019 22:33
Serve own liquidity using @0x/asset-swapper
const ownOrder: AssetSwapper.SignedOrder = {...}
const customBook = AssetSwapper.Orderbook.getOrderbookForProvidedOrders([
ownOrder
]);
const quoter = new AssetSwapper.SwapQuoter(
provider,
customBook
);
const order = await quoter.getMarketBuySwapQuoteAsync(
contractAddress,
@coopermaruyama
coopermaruyama / keybase.md
Created September 11, 2019 21:02
keybase.md

Keybase proof

I hereby claim:

  • I am coopermaruyama on github.
  • I am cooperm (https://keybase.io/cooperm) on keybase.
  • I have a public key ASBCWPJ3o0p1okDCyXJ6TKfl_G0H-OKxFDUlM1dspiuRBwo

To claim this, I am signing this object:

@coopermaruyama
coopermaruyama / condorcet.js
Last active July 20, 2018 22:27
Condorcet vote w/ staking
const candidates = [
'A',
'B',
'C',
'D'
]
const votes = [
['B', 'C', 'A', 'D'],
['B', 'C', 'A', 'D'],
@coopermaruyama
coopermaruyama / script.js
Last active February 2, 2018 01:01
find price at time
const moment = require('moment');
function findPrice(prices, targetMoment) {
const match = prices.find((data) => {
const [ts] = data;
const momentPrice = moment(ts);
return momentPrice.isSame(targetMoment, 'day');
});
const res = match && match[1];
@coopermaruyama
coopermaruyama / gist:7d869014c86c1b3e039468d43fff2f5a
Created December 4, 2017 18:51
ICOStats simple API query example using curl
curl \
-X POST \
-H "Content-Type: application/json" \
--data '{ "query": "{ icos { id, name, symbol, roi_since_ico } }" }' \
https://icostats.com/graphql
pragma solidity ^0.4.15;
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
contract SafeProxy is Ownable {
mapping(address => bool) public whitelistedAddress;
event TransferFunds(address sender, address receiveingAddr);
/// @dev Adds a new address to the whitelist