Skip to content

Instantly share code, notes, and snippets.

View scott-maddox's full-sized avatar

Scott Maddox scott-maddox

View GitHub Profile
@scott-maddox
scott-maddox / unguessable_uuid.py
Created January 25, 2021 18:42
Generate unguessable random unique IDs in python
# 24 bytes (192 bits) is more than sufficient to make any ID unguessable.
# If you're insanely paranoid, you can bump this to 48 bytes (384 bits).
#
# If you want to use a number of bytes that is not a multiple of 24,
# then you will need to strip the '=' characters from the end of the
# byte string generated by urlsafe_b64encode.
# See https://neilmadden.blog/2018/08/30/moving-away-from-uuids/ for how to
# estimate the amount of time it would require to guess an ID.
@scott-maddox
scott-maddox / hover_line_plots.py
Created July 25, 2019 16:47
chaco line plots with line labels on hover
from numpy import array, inf, linspace
from scipy.special import jn
from chaco.api import ArrayDataSource, ArrayPlotData, DataLabel, Plot
from chaco.tools.api import SimpleInspectorTool
from enable.api import BaseTool, ComponentEditor
from traits.api import HasTraits, Instance, on_trait_change
from traitsui.api import Item, View
from traits.api import HTML, HasStrictTraits
from traitsui.api import UItem, View
class Test(HasStrictTraits):
html = HTML
traits_view = View(UItem('html'))
def _html_default(self):
return """
from traits.api import (HasTraits, Instance, Int, List, Property, Unicode,
on_trait_change)
from traitsui.api import HGroup, ModelView, UItem, View
COLUMNS_WIDTH = 200
class Case(HasTraits):
param1 = Unicode
param2 = Unicode
from chaco.api import ArrayPlotData, GridContainer, Plot
from chaco.example_support import COLOR_PALETTE
from chaco.tools.api import PanTool, ZoomTool
from enable.api import ComponentEditor
from numpy import linspace
from scipy.special import jn
from traits.api import HasTraits, Int, Property
from traitsui.api import Group, Item, View
@scott-maddox
scott-maddox / showbest.js
Last active July 8, 2017 13:51 — forked from thexa4/showbest.js
For use with spaceplan
// Paste in console
var getThings = function(){
var divs = [...document.querySelectorAll("#manufacture__container > div")]
var things = divs.map(function(e){
var result = {e};
var spans = [...e.getElementsByTagName("span")]
spans.map(function(s){
var str = s.innerText.replace(/[^/.0-9]/g, '');
var a = str.split("/");
var num = +a[0];
@scott-maddox
scott-maddox / math.go
Last active November 28, 2015 21:05
Inlining simple math stub functions fails
package main
import (
"fmt"
"math"
)
func Sqr2() float64 {
return 2.0*2.0
}
@scott-maddox
scott-maddox / no_generics_needed.go
Last active August 26, 2015 23:55
An alternative solution to the problem posed in this blog post: http://www.onebigfluke.com/2014/12/generic-programming-go-generate.html
package main
import (
"fmt"
"strings"
)
type Person struct {
FirstName string
LastName string