Skip to content

Instantly share code, notes, and snippets.

@ppelleti
ppelleti / TestSpookyV2.cpp
Created April 23, 2022 20:06
version of Bob Jenkins' TestSpookyV2.cpp which works on UNIX as well as Windows
#include "SpookyV2.h"
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@ppelleti
ppelleti / svg-to-dxf.pl
Created May 4, 2016 02:22
Convert SVG files to DXF files on Mac OS X
#!/usr/bin/perl -w
# svg-to-dxf.pl - convert SVG files to DXF files on Mac OS X
# by Patrick Pelletier, public domain (or cc0)
# based on the commands suggested here:
# https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_2D_formats
# assumes Inkscape.app is installed in /Applications
# and pstoedit is installed in PATH, such as via "brew install pstoedit"
use Cwd qw(abs_path);
@ppelleti
ppelleti / Diffie.java
Created August 19, 2013 23:35
A simple program which will detect the maximum Diffie-Hellman size supported by the JRE.
import java.security.AlgorithmParameterGenerator;
import java.security.InvalidParameterException;
public class Diffie {
public static void main (String[] args) throws Exception {
AlgorithmParameterGenerator apg = AlgorithmParameterGenerator . getInstance ("DiffieHellman");
int good = 0;
for (int i = 512 ; i <= 16384 ; i += 64) {
try {
apg . init (i);
@ppelleti
ppelleti / feather.txt
Created August 31, 2018 19:40
Feather pinout ASCII art
This is an unofficial pinout diagram of the Adafruit Feather
specification:
https://learn.adafruit.com/adafruit-feather/feather-specification
For more information about this diagram, see:
http://funwithsoftware.org/posts/2018-08-31-feather-ascii-art-pinout.html
+-------------------+
@ppelleti
ppelleti / Relay_DPDT_Panasonic_JW2.py
Created July 24, 2017 21:54
script to generate KiCad footprint for Panasonic JW2 relay
#!/usr/bin/env python3
import sys
sys.path.append("/Users/ppelleti/src/kicad-footprint-generator")
from KicadModTree import *
footprint_name = "Relay_DPDT_Panasonic_JW2"
f = Footprint(footprint_name)
@ppelleti
ppelleti / alitove_with_button.ino
Last active December 24, 2016 17:55
Arduino sketch for displaying several different patterns of lights on WS2811/WS2812 LEDs, controlled by a pushbutton.
/* This Arduino sketch is for controlling a string of Alitove lights
* from an Adafruit Trinket. The lights are connected to the
* Trinket's pin 1 through a resistor. A pushbutton is connected from
* pin 0 to ground. You can use the pushbutton to cycle through the
* following modes:
*
* 1. Solid purple
* 2. Blue with white twinkles
* 3. Rainbow
* 4. Multicolored blinking
@ppelleti
ppelleti / Setup.hs
Last active August 12, 2016 07:09
copy photos from my phone using Android Debug Bridge
import Distribution.Simple
main = defaultMain
@ppelleti
ppelleti / rand-trouble.c
Created August 21, 2013 06:33
This is a simple program which demonstrates that OpenSSL's default random number generator is not fork-safe if the pids wrap.
/* Patrick Pelletier, public domain / cc0
*
* OpenSSL's default random number generator (RAND_SSLeay) is not
* fork-safe in the case where the child pids wrap around without the
* parent having used or reseeded the RNG in the interim. Which makes
* this a rare problem, but one which recently cropped up on Android:
* https://plus.google.com/+AndroidDevelopers/posts/YxWzeNQMJS2
* and Nikolay Elenkov wrote a program to demonstrate the bug on Android:
* https://gist.github.com/nelenkov/581f9be65dcc0b6b35b9
*
@ppelleti
ppelleti / strings returned by FormatMessage
Created February 8, 2013 01:30
A comparison of the error strings returned by evutil_socket_error_to_string, versus the error strings returned by the Windows function FormatMessage.
WSAEINTR -> "A blocking operation was interrupted by a call to WSACancelBlockingCall."
WSAEACCES -> "An attempt was made to access a socket in a way forbidden by its access permissions."
WSAEFAULT -> "The system detected an invalid pointer address in attempting to use a pointer argument in a call."
WSAEINVAL -> "An invalid argument was supplied."
WSAEMFILE -> "Too many open sockets."
WSAEWOULDBLOCK -> "A non-blocking socket operation could not be completed immediately."
WSAEINPROGRESS -> "A blocking operation is currently executing."
WSAEALREADY -> "An operation was attempted on a non-blocking socket that already had an operation in progress."
WSAENOTSOCK -> "An operation was attempted on something that is not a socket."
WSAEDESTADDRREQ -> "A required address was omitted from an operation on a socket."
@ppelleti
ppelleti / hokey-hash.rs
Created August 12, 2012 10:00
list of hokey hash functions in rustc
/* list of hokey hash functions in rustc as of August 12, 2012
* in response to https://github.com/mozilla/rust/issues/3041 */
// libsyntax/ast_util.rs:
pure fn hash_ty(t: &@ty) -> uint {
let res = (t.span.lo << 16u) + t.span.hi;
return res;
}