Skip to content

Instantly share code, notes, and snippets.

@joshmurr
joshmurr / time_series_generator.py
Created March 30, 2021 10:49
Python Generator Example
import matplotlib.pyplot as plt
import numpy as np
def generate_time_series(batch_size, n_steps):
f1, f2, off1, off2 = np.random.rand(4)
n = 0
noise = 0.1 * (np.random.rand(batch_size * n_steps) - 0.5)
time = np.linspace(0, 1, n_steps)
while n < batch_size:
series = 0.5 * np.sin((time - off1) * (f1 * 10 + 10))
@joshmurr
joshmurr / simple_request.py
Created February 12, 2021 12:08
Simple Request
import requests
from bs4 import BeautifulSoup
def get_data(url):
page = requests.get(url)
soup = BeautifulSoup(page.content)
return soup
@joshmurr
joshmurr / index.html
Last active December 1, 2020 17:05
Dynamically setting type in HTML Canvas.
<canvas></canvas>
<script src='script.js'></script>
<div class="items a">
<h3>A</h3>
<p>a first thing</p>
<p>another thing</p>
<p>another thing</p>
<p>another thing</p>
<p>another thing</p>
</div>
<div class="items b">
<p>banother thing</p>

Multiple Sticky Titles with CSS and JS

On some mobile platforms there are alphabetical lists that use the letter as a title. As you scroll down the list the title follows you until you get to the next one. This snippet emulates this functionality.

A Pen by Chris Spittles on CodePen.

License.

@joshmurr
joshmurr / floyd-steinberg_dither_processing.pde
Created December 17, 2013 01:43
Floyd-Steinberg Dither Algorithm for Processing
color[] colorPalette = new color[] {
color(0, 0, 0),
color(0, 0, 255),
color(0, 255, 0),
color(0, 255, 255),
color(255, 0, 0),
color(255, 0, 255),
color(255, 255, 0),
color(255, 255, 255)
};
@joshmurr
joshmurr / all_possible_combinations.pde
Created November 15, 2013 11:56
A rather concise All Possible Combinations algorithm for Processing.
ArrayList<String> letters;
ArrayList<String> combo;
int n=6;
int k=n;
void go(int offset, int k) {
if (k==0) {
println(combo);
return;
}
@joshmurr
joshmurr / particle.js
Last active December 27, 2015 08:29
Turns an image into moving particles.
var w,h,partcounter;
var canvas, ctx;
var mousex, mousey;
function map(value, low1, high1, low2, high2) {
return low2 + (high2 - low2) * (value - low1) / (high1 - low1);
}
function vec(x_, y_){
this.x = x_;