Skip to content

Instantly share code, notes, and snippets.

@formigone
formigone / notebook.json
Created January 25, 2020 21:57
My personal Jupyter Notebook settings.` ~/.jupyter/nbconfig/notebook.json`
{
"toc2": {
"number_sections": false,
"skip_h1_title": false,
"toc_cell": false
},
"load_extensions": {
"plotlywidget/extension": true,
"jupyter-js-widgets/extension": true,
"contrib_nbextensions_help_item/main": true,
@formigone
formigone / arxiv-abstracts-to-markdown.py
Created December 3, 2019 17:37
Simple Python script that scrapes the first 200 abstracts (with author list and Arxiv ID) from arxiv.org for a given query string, and renders list in Markdown.
'''
The purpose of this script is to quickly collect a large number of abstracts
from argiv.org so to simplify scanning lots of documents on a single topic
before committing the time to do an in-depth reading of any particular paper.
@author formigone
'''
import requests
import re
@formigone
formigone / dataclass_defaults_p36.py
Created November 25, 2019 21:25
A poor man's dataclass not using @DataClass for backwards compat with Python 3.6, based on namedtuples.
from collections import namedtuple
_Activity = namedtuple('Activity', ['activityId', 'studentId', 'timeRead'])
_Activity.__new__.__defaults__ = (None, None, 0.0)
class Activity(_Activity):
@staticmethod
def from_dict(args):
args = {k: v for k, v in args.items() if k in _Activity._fields}
@formigone
formigone / custom.css
Last active April 24, 2023 12:56
Custom CSS for Jupyter Notebook web application
#notebook-container{
box-shadow: none !important;
}
.container {
width: 80% !important;
}
.notebook_app {
background: #fff !important;
@formigone
formigone / appsync_fetch.py
Last active September 11, 2018 23:59
Fetching data from AWS AppSync
query = '''
{
users {
id
created
firstName
lastName
email
}
}
@formigone
formigone / model.py
Created January 27, 2018 18:11
A simple RNN model using Tensorflow 1.4 Estimator API
def model_fn(features, labels, mode, params):
word_vec = embed_sequence(features, vocab_size=params['vocab_size'], embed_dim=params['embed_size'])
# [-1, seq_len, embed_size]
word_list = tf.unstack(word_vec, axis=1)
# [-1, embed_size]
cell = tf.nn.rnn_cell.GRUCell(params['embed_size'])
_, encoding = tf.nn.static_rnn(cell, word_list, dtype=tf.float32)
@formigone
formigone / tfrecord_utils.py
Created December 21, 2017 06:24
Creating and using TensorFlow TFRecords
def list_to_tfrecord(list, tfrecord_filename):
"""
Convert a list of (features, labels) to a TFRecord file.
param list: a list of tuples with (feature, label)
"""
with python_io.TFRecordWriter(tfrecord_filename) as writer:
for feature, label in list:
example = tf.train.Example()
example.features.feature['x'].float_list.value.extend(features)
@formigone
formigone / matrix_transpose.js
Created July 20, 2017 02:45
Computes the transpose of a matrix represented by a 2-dimensional array
function transpose(mat){
return mat[0].map((_, y) => {
return mat.map((_, x) => {
return mat[x][y];
});
});
}
var mat0 = [
[0, 1, 2, 3, 4],
@formigone
formigone / matrix_multipication.js
Created July 20, 2017 02:18
Multiply two matrices represented by 2-dimensional arrays
function mult(a, b){
return a.map((row) => {
return b[0].map((col, j) => {
return row.reduce((acc, a0, i) => (acc + a0 * b[i][j]), 0);
});
})
}
var mat0 = [
[1, 2, 3, 4],
@formigone
formigone / react-custom-html5-video-player.html
Last active May 13, 2016 14:24
A plain HTML5 video player styled to taste, and driven by React.js
<!doctype html>
<html>
<head>
<title>mp4</title>
<style>
.emVid {
position: relative;
bottom: 0;
left: 0;