Skip to content

Instantly share code, notes, and snippets.

View johanastborg's full-sized avatar
🧭
Dreaming in Code

Johan Astborg johanastborg

🧭
Dreaming in Code
  • Sweden
View GitHub Profile
//https://docs.google.com/presentation/d/1bnDuaUqqDM8uh_dZD_JbfCIMtA5U4iP8mazT4h21yDI
function onOpen() {
let ui = SlidesApp.getUi();
ui.createMenu('Custom Menu')
.addItem('Populate Donut Chart', 'showPrompt')
.addSeparator()
.addSubMenu(ui.createMenu('Sub-menu')
.addItem('Second item', 'menuItem2'))
@johanastborg
johanastborg / parse.py
Created May 27, 2021 13:22
Extract endpoint info from proto3 files
import re
# Ref: https://cloud.google.com/endpoints/docs/grpc/transcoding
regexparse = r'option\ \(google.api.http\)\ =\s{\s+(\w+: \"[\S]+)\s+(\w+:\s\"[\S]+\s+)?};'
with open('http_bookstore.proto','r') as file:
content = file.read()
[print(x.group()) for x in re.finditer(regexparse, content)]
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const Busboy = require('busboy');
const os = require('os');
const fs = require('fs');
// create express app
const app = express();
var public = path.join(__dirname, 'public');
@johanastborg
johanastborg / naive.py
Last active November 10, 2020 21:08
Naive Serving using Flask
import json
from flask import Flask
from keras.models import load_model
from utils import preprocess
model = load_model('model.h5')
app = Flask(__name__)
@app.route('/forecast', methods=['POST'])
def forecast():
@johanastborg
johanastborg / tickers.dat
Created September 14, 2020 22:29
Nasdaq 100 tickers
ATVI
ADBE
AMD
ALXN
ALGN
GOOGL
GOOG
AMZN
AMGN
ADI
@johanastborg
johanastborg / fsutils.js
Created September 12, 2020 15:49
List and delete files
const dir = '/tmp';
// list content
fs.readdir(dir, (_, files) => { console.log(files.join('\n')) });
// delete files (ignore permission errors)
fs.readdir(dir, (_, files) => { files.forEach(file => { fs.unlink(`${dir}/${file}`, _ => _)})});
@johanastborg
johanastborg / erc.js
Last active September 11, 2020 07:31
Expected number of entries on an hourly basis
function expectedRowCount(ts1, ts2) {
let d1 = new Date(ts1);
let d2 = new Date(ts2);
let ms_diff = d2 - d1;
return ms_diff / (3.6e6) + 1;
}
// expectedRowCount('2020-09-07 10:00:00 UTC', '2020-09-10 06:00:00 UTC');
// => 69
@johanastborg
johanastborg / imvolsolver.py
Created July 8, 2020 08:47
Solver for implied vol.
import numpy as np
def pow(x, n):
return np.exp(n * np.log(x))
def cnd(x):
a1 = 0.31938153
a2 = -0.356563782
a3 = 1.781477937
a4 = -1.821255978
@johanastborg
johanastborg / grammar.py
Created June 28, 2020 14:03
POS tagging using python
import nltk
#sentence = """John waited for us at the bus stop."""
def parse(sentence):
tokens = nltk.word_tokenize(sentence)
tagged = nltk.pos_tag(tokens)
print(tagged)
@johanastborg
johanastborg / angle2.py
Last active June 26, 2020 15:57
Angles between vectors using a non-standard inner product
def angle2(xx,yy,A):
t = (xx.T@A@yy)/(np.sqrt(xx@A@xx.T*yy.T@A@yy))
return np.arccos(t)
def angle1(xx,yy):
t = (xx.T@yy)/(np.sqrt(xx@xx.T*yy.T@yy))
return np.arccos(t)