Skip to content

Instantly share code, notes, and snippets.

@qpwo
qpwo / johnson.py
Last active September 3, 2017 14:27
common python form of networkx's implementation of Johnson's cycle finding algorithm
from collections import defaultdict
def simple_cycles(G):
def _unblock(thisnode,blocked,B):
stack = set([thisnode])
while stack:
node = stack.pop()
if node in blocked:
blocked.remove(node)
stack.update(B[node])
@qpwo
qpwo / goodmorning.py
Created October 4, 2017 01:32
Solution to problem A in tonight's contest, with explanation of hashmaps
# A 'map' also known as a 'dictionary' also known as a 'hashmap':
# https://en.wikipedia.org/wiki/Hash_table
# It maps 'keys' to 'values'. Keys and values can be anything: strings, tuples, integers, floats...
# Here, the keys are integers and the values are lists of integers.
d = {
1: [1,2,3,4,5,6,7,8,9,0],
2: [2,3,5,6,8,9,0],
3: [3,6,9],
4: [4,5,6,7,8,9,0],
5: [5,6,8,9,0],
@qpwo
qpwo / test.py
Last active November 18, 2017 22:26
#! /usr/bin/python
# -*- coding: utf8 -*-
""" GAN-CLS """
import tensorflow as tf
import tensorlayer as tl
from tensorlayer.layers import *
from tensorlayer.prepro import *
from tensorlayer.cost import *
import numpy as np
@qpwo
qpwo / details.md
Created November 25, 2017 16:20
quora details

Real brains do not organize neurons into layers. It's a messy process where one neuron could connect directly to the input and the output, while another neuron is in a long chain, while a third neuron is connected to twenty different nodes at different depths. Who decided that artificial neural networks should be very constrained in terms of shape? Is it computational convenience, or does it actually work better?

@qpwo
qpwo / lukemath.js
Last active March 11, 2018 22:13
A minimal possible working example of a javascript library
var lukemath = new (function() {
var privatePi = 3.14;
this.tau = 2 * privatePi;
var privateSquare = function(n) {
return n * n;
}
this.fourth = function(n) {
return privateSquare(privateSquare(n));
}
})();
@qpwo
qpwo / ideal-conf-file.conf
Last active June 14, 2018 20:22
The conf file for a run of "mastml from the future" where all the important features have been added
# You run this with `$ python mastml.py settings.conf data.csv -o results/`
# Second example: `$ python mastml.py input.conf compositions.csv -o Desktop/model-results/`
# Or you open the website, upload a csv, upload a conf file, and download the resulting zip file
# Sections and subsections are in CamelCase; parameters are in snake_case
[GeneralSetup]
input_features = Auto # Defaults to all but last column (specifying Auto is same as omiting this option)
@qpwo
qpwo / traveling salesman - simulated annealing.ipynb
Created September 21, 2018 19:23
A simulated annealing solution to traveling salesman problem, using python3 and numpy
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@qpwo
qpwo / drifting-bandit.jl
Created February 24, 2019 15:38
Sutton & Barto 2018 Exercise 2.5: Comparing sample averages and constant step size when the arm distributions drift across time (julia)
# Luke Miles
# February 2019
# Drifting arm distribution demo
# (Public domain dedication)
using PyPlot
const num_trials = 1000
const num_pulls = 10000
const ε = 0.1
@qpwo
qpwo / output.txt
Created June 14, 2019 18:02
Kotlin unstoppable exception (threading)
A
B
C
D
Exception in thread "DefaultDispatcher-worker-1" java.lang.ArithmeticException: / by zero
at CoolKt$main$1$f$1$1.invokeSuspend(cool.kt:17)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:238)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
@qpwo
qpwo / settings.json
Created May 26, 2020 20:39
barebones vscode settings (hide all UI elements like minimap and tab bar)
{
"telemetry.enableTelemetry": false,
"telemetry.enableCrashReporter": false,
"editor.minimap.enabled": false,
"editor.lineNumbers": "off",
"workbench.activityBar.visible": false,
"workbench.statusBar.visible": false,
"workbench.editor.showTabs": false,
"editor.glyphMargin": false,
"editor.folding": false,