Skip to content

Instantly share code, notes, and snippets.

@bengrunfeld
bengrunfeld / make_ndb_return_data_json_serializable.py
Last active September 5, 2018 18:59
Convert NDB result to JSON Serializable data
def make_ndb_return_data_json_serializable(data):
"""Build a new dict so that the data can be JSON serializable"""
result = data.to_dict()
record = {}
# Populate the new dict with JSON serializiable values
for key in result.iterkeys():
if isinstance(result[key], datetime.datetime):
record[key] = result[key].isoformat()
@bengrunfeld
bengrunfeld / webapp2_headers
Created January 13, 2015 21:09
Webapp2 Headers
"""
Sometimes you need to forcefully set headers in Webapp2 while using Google App Engine (GAE).
It is NOT RECOMMENDED to use `*` for `Access-Control-Allow-Origin` as below. I've put it
there simply for the sake of demonstration. Make sure you choose something more restrictive.
"""
def initialize_headers(headers, http_verb):
"""Set up the headers for HTTP requests"""
headers['Access-Control-Allow-Origin'] = '*'
" Use spaces instead of tabs. Use 4 spaces when User presses the tab button. Display line numbers
set expandtab tabstop=4 shiftwidth=4 softtabstop=4 number
retab
" Syntax highlighting
syntax on
" Color any column past 79 chars for Python PEP-8 compliance
set colorcolumn=80
# Gunicorn Shortcuts
alias p='pstree -ap|grep gunicorn'
alias k='kill -HUP'
# New with Ubuntu 14.04 LTS update, I think
alias c='sudo cp -r /home/vagrant/tetralytics/src/static/dist /home/vagrant/tt-server/src/static/;
sudo cp -r /home/vagrant/tetralytics/src/templates /home/vagrant/tt-server/src'
@bengrunfeld
bengrunfeld / arbitrage_targets.txt
Created January 1, 2018 06:47
Arbitrage Targets
BEST COINS FOR ARBITRAGE:
1. Verge
Low: BTC 0.00001100
High: BTC 0.00001600
Profit: 45%
2. Tron
Low: BTC 0.00000250
High: BTC 0.00000315
@bengrunfeld
bengrunfeld / page-source.html
Created January 2, 2018 18:54
Credible.dev Page Source
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>credible &#8211; Just another WordPress site</title>
<link rel='dns-prefetch' href='//fonts.googleapis.com' />
<link rel='dns-prefetch' href='//s.w.org' />
@bengrunfeld
bengrunfeld / open.js
Last active January 8, 2018 04:55
Quickly open browser tabs
const c1 = target => {
const pre = 'https://www.binance.com/tradeDetail.html?symbol='
window.open(`${pre}${target}_BTC`, '_blank')
}
const c2 = target => {
const pre = 'https://www.binance.com/tradeDetail.html?symbol='
window.open(`${pre}${target}_ETH`, '_blank')
}
@bengrunfeld
bengrunfeld / concurrent-asynchronous-requests-nodejs.md
Last active August 13, 2018 01:25
Concurrent Asynchronous Requests in Node.js (Javascript) using Async/Await

Concurrent Requests in Node.js (Javascript) using Async/Await

To make concurrent asynchronous requests in NodeJS (Javascript), we can take advantage of the setTimeout function and use it together with async/await, plus trusty old count.

What we are aiming for here is that 3 requests get sent asynchronously, but the promise they're contained in only resolves when ALL 3 have returned. If it takes too long, we want to reject the promise, since the data has likely become stale.

Originally I tried using Promise.all(), but ran into problems with it. The following implementation worked

@bengrunfeld
bengrunfeld / logs.txt
Created February 6, 2019 04:28
From Stack Overflow question: "AWS Elastic Beanstalk with ALB: Node Websocket times out"
# From Stack Overflow question: "AWS Elastic Beanstalk with ALB: Node Websocket times out"
-------------------------------------
/var/log/nodejs/nodejs.log
-------------------------------------
> tradey@1.0.0 start /var/app/current
> node ./dist/server.js
Prod: App listening to 8081....
Press Ctrl+C to quit.
@bengrunfeld
bengrunfeld / helloWorld.js
Created March 4, 2019 03:17
Just a simple bit of code for example purposes
const sayHello = () =>
console.log('Hello, World')
sayHello()