Skip to content

Instantly share code, notes, and snippets.

View bruce965's full-sized avatar
🕷️

Fabio Iotti bruce965

🕷️
View GitHub Profile
@bruce965
bruce965 / resize-sensor.ts
Last active September 29, 2018 19:13
TypeScript Element Resized Sensor
import classes from './style.less';
const CLASSNAME_RESIZE_SENSOR = classes['resize-sensor'];
export interface ResizeSensorOptions {
element: HTMLElement;
onResize(): void;
}
/**
@bruce965
bruce965 / STM32F103C_USB_MIDI_Keyboard.ino
Last active July 14, 2018 12:07
Code for my 61-keys USB MIDI keyboard made with 1x STM32F103C8T6 and 8x 74HC165 ICs.
#include <USBMIDI.h>
// we use 74HC165 8-bit shift register ICs
#define CLOCK_ENABLE_PIN PB4
#define PARALLEL_LOAD_PIN PB7
#define CLOCK_PIN PB6
#define SERIAL_DATA_PIN PB8
#define FIRST_NOTE (60 - 12*2) // leftmost note of the keyboard (60 is middle C)
#define NOTES_COUNT (5 * 12 + 1) // number of notes
@bruce965
bruce965 / code.ts
Last active February 19, 2017 16:20
Algorithm to check if a point is inside a self-crossing polygon. http://codepen.io/anon/pen/ygdOWp
/// <reference path="https://cdn.rawgit.com/borisyankov/DefinitelyTyped/master/jquery/jquery.d.ts" />
interface Vector2 { x: number; y: number; }
interface Line { a: Vector2; b: Vector2; }
var drawString: (point: Vector2, string: string, color?: string) => void;
var drawPoint: (point: Vector2, color?: string, radius?: number) => void;
var drawLine: (line: Line, color?: string, thickness?: number) => void;
var intersect: (a: Line, b: Line, upInclusive?: boolean, downInclusive?: boolean) => Vector2 | null;
var angleBetweenNormalized: (a: Vector2, b: Vector2, origin?: Vector2) => number;
@bruce965
bruce965 / Singleton.cs
Last active December 9, 2015 09:23
Unity Singleton
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using UnityEngine;
namespace SandWar.Unity.Tools
{
/// <summary>
/// Attributes to be used with <see cref="Singleton&lt;T&gt;" />s.
@bruce965
bruce965 / ModelPreview.cs
Created November 12, 2015 13:02
Unity ModelPreview
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace SandWar.Unity.Tools
{
[AddComponentMenu("")]
public sealed class ModelPreview : Singleton<ModelPreview>
{
static readonly int TemporaryLayer = 31;
@bruce965
bruce965 / FocusConfiner.ts
Created June 20, 2015 20:20
Confine focus inside a limited set of elements
/// <reference path="../../defs/jquery/jquery.d.ts" />
module fg.dom {
// get the next element in a JQuery set (returns the first element if 'current' is the last in the set)
var nextElement = (set: JQuery, current: Element) => {
var index = set.index(current);
if (index < set.length - 1)
return set.get(index + 1);
@bruce965
bruce965 / build.bat
Created March 26, 2015 09:22
Simple Physics Simulation
@tsc --sourceMap --out out/physics.js Physics.ts
@if not "%errorlevel%"=="0" @pause
@bruce965
bruce965 / FileSaver.min.js
Created March 26, 2015 09:09
JavaScript Virtual CPU
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
var saveAs=saveAs||"undefined"!==typeof navigator&&navigator.msSaveOrOpenBlob&&navigator.msSaveOrOpenBlob.bind(navigator)||function(a){"use strict";if("undefined"===typeof navigator||!/MSIE [1-9]\./.test(navigator.userAgent)){var k=a.document,n=k.createElementNS("http://www.w3.org/1999/xhtml","a"),w="download"in n,x=function(c){var e=k.createEvent("MouseEvents");e.initMouseEvent("click",!0,!1,a,0,0,0,0,0,!1,!1,!1,!1,0,null);c.dispatchEvent(e)},q=a.webkitRequestFileSystem,u=a.requestFileSystem||q||a.mozRequestFileSystem,
y=function(c){(a.setImmediate||a.setTimeout)(function(){throw c;},0)},r=0,s=function(c){var e=function(){"string"===typeof c?(a.URL||a.webkitURL||a).revokeObjectURL(c):c.remove()};a.chrome?e():setTimeout(e,10)},t=function(c,a,d){a=[].concat(a);for(var b=a.length;b--;){var l=c["on"+a[b]];if("function"===typeof l)try{l.call(c,d||c)}catch(f){y(f)}}},m=function(c,e){var d=this,b=c.type,l=!1,f,p,k=function(){t(d,["w
@bruce965
bruce965 / W3CValidator.js
Created September 4, 2014 18:31
W3C Validator Bookmarklet
javascript:(function(){var%20form=document.createElement("form");form.style.display='none';form.setAttribute("method","post");form.setAttribute("action","http://validator.w3.org/check");var%20hiddenField=document.createElement("input");hiddenField.setAttribute("name","fragment");hiddenField.setAttribute("value",'<!DOCTYPE%20'+document.doctype.name+(document.doctype.publicId?'%20PUBLIC%20"'+document.doctype.publicId+'"':'')+(!document.doctype.publicId&&document.doctype.systemId?'%20SYSTEM':'')+(document.doctype.systemId?'%20"'+document.doctype.systemId+'"':'')+'>\n'+document.documentElement.outerHTML);form.appendChild(hiddenField);document.body.appendChild(form);form.submit();})();
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Fabiogiopla.Utilities.Hotkey
{
[Serializable]
public sealed class HotkeyHandler : IEquatable<HotkeyHandler>, ICloneable
{
private const int ALT = 0x0001;