Skip to content

Instantly share code, notes, and snippets.

View benbotto's full-sized avatar
💭
Because code.

benbotto

💭
Because code.
View GitHub Profile
@benbotto
benbotto / gcd.sass
Created May 23, 2017 22:27
Greatest common divisor function in SASS
@function gcd($a, $b) {
@if $b == 0 {
@return $a;
}
@return gcd($b, $a%$b);
}
@for $i from 1 through 11 {
@for $j from $i+1 through 12 {
@benbotto
benbotto / Temp.java
Last active September 17, 2019 00:41
Modified http://www.cs.ubc.ca/~poole/demos/mdp/vi.html to work as a JFrame
import java.awt.Dimension;
public class Temp {
public static void main(String[] args) {
VIgui gui = new VIgui();
gui.pack();
gui.setSize(new Dimension(1024, 768));
gui.setVisible(true);
}
}
@benbotto
benbotto / loss.py
Created February 12, 2018 21:34
huber_loss for Tensorflow Keras
def huber_loss(y_true, y_pred, clip_delta=1.0):
error = y_true - y_pred
cond = tf.keras.backend.abs(error) < clip_delta
squared_loss = 0.5 * tf.keras.backend.square(error)
linear_loss = clip_delta * (tf.keras.backend.abs(error) - 0.5 * clip_delta)
loss = tf.where(cond, squared_loss, linear_loss)
return tf.keras.backend.mean(loss)
@benbotto
benbotto / quadratic.cpp
Last active May 26, 2019 16:54
Sequentially Indexing Permutations O(n^2)
#include <array>
using std::array;
#include <iostream>
using std::cout;
using std::endl;
unsigned factorial(unsigned n)
{
return n <= 1 ? 1 : n * factorial(n - 1);
}
@benbotto
benbotto / linear.cpp
Last active May 26, 2019 03:13
Sequentially Indexing Permutations O(n)
#include <array>
using std::array;
#include <bitset>
using std::bitset;
#include <iostream>
using std::cout;
using std::endl;
unsigned factorial(unsigned n)
{
@benbotto
benbotto / generic.cpp
Last active May 26, 2019 15:47
Sequentially Indexing Permutations O(n) (Generic)
#include <cstddef>
using std::size_t;
#include <array>
using std::array;
#include <bitset>
using std::bitset;
#include <iostream>
using std::cout;
using std::endl;
@benbotto
benbotto / Rectangle.js
Created March 25, 2020 14:59
Rectangle rotating at the origin.
class Rectangle {
constructor(gl, color, width, height) {
this.gl = gl;
this.color = color;
this.width = width;
this.height = height;
this.rotation = gl.mat2d.create();
}
@benbotto
benbotto / rectangle-rotating-at-point.js
Created March 25, 2020 15:44
A rectangle rotating at a point.
class Rectangle {
constructor(gl, color, width, height) {
this.gl = gl;
this.color = color;
this.width = width;
this.height = height;
// Rotation, updated before each render.
this.rotation = gl.mat2d.create();
@benbotto
benbotto / rectangle-orbiting-about-origin.js
Last active March 25, 2020 16:21
A rectangle orbiting about the origin.
class Rectangle {
constructor(gl, color, width, height) {
this.gl = gl;
this.color = color;
this.width = width;
this.height = height;
// Rotation, updated before each render.
this.rotation = gl.mat2d.create();
@benbotto
benbotto / rectangle-orbiting-about-point.js
Created March 25, 2020 17:01
A rectangle orbiting about a point.
class Rectangle {
constructor(gl, color, width, height) {
this.gl = gl;
this.color = color;
this.width = width;
this.height = height;
// Rotation, updated before each render.
this.rotation = gl.mat2d.create();