Skip to content

Instantly share code, notes, and snippets.

View andrewbranch's full-sized avatar

Andrew Branch andrewbranch

View GitHub Profile
@andrewbranch
andrewbranch / Country.ascx
Last active November 4, 2023 11:01
Easy state and country dropdowns for MVC .NET, current as of 8/2013
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
<% string defaultCountry = "United States";
if (ViewData.ContainsKey("default")) {
defaultCountry = (string)ViewData["default"];
}
%>
<select id="<%= Html.IdFor(model => model) %>" name="<%= ViewData.TemplateInfo.HtmlFieldPrefix %>"<% if (ViewData.ContainsKey("html")) { foreach (var a in HtmlHelper.AnonymousObjectToHtmlAttributes(ViewData["html"])) { %> <%= a.Key %>="<%= a.Value %>"<% } } %>>
<% if (String.IsNullOrWhiteSpace(Model) && !Inspect.Models.Location.Countries.Keys.Contains(defaultCountry)) { %><option value="<%: defaultCountry %>"><%: defaultCountry %></option><% } %>
<% foreach (var country in Inspect.Models.Location.Countries.Keys) { %>
@andrewbranch
andrewbranch / writing-type-definitions.md
Last active November 3, 2023 19:07
Writing type definitions, on a scale of 1–5

Writing type definitions, on a scale of 1–5

By hand With tsc With 3rd party tool
Ease 1 5 4
Avg. correctness 2 5 2
Flexibility 5 1 3
@andrewbranch
andrewbranch / tsc-ts-vs-dts.md
Last active September 25, 2023 16:23
tsc performance consuming .ts vs .d.ts files in npm packages

Original Tweet

tsc performance consuming .ts vs .d.ts files in npm packages

What if TypeScript libraries published just .ts sources to npm instead of .js and .d.ts files? This might already be tempting for Bun-only libraries, but how will that impact users? This is easy to answer by experimenting on existing libraries that ship .js, .d.ts, and .ts files.

RxJS ships .js and .d.ts files, but also .ts files for debugability purposes. By tweaking its package.json "exports", we can compare tsc performance on this file with imports resolving to .d.ts files vs .ts source files:

import {} from "rxjs";
@andrewbranch
andrewbranch / autoshrink.js
Last active July 31, 2019 22:07
Responds to window resize events. Max font size taken from initial font size (specify with CSS).
(function($) {
function getTextWidth($element) {
var tester = $("<div/>").text($element.text())
.css({ "position": "absolute", "float": "left", "white-space": "nowrap", "visibility": "hidden", "font": $element.css("font"), "text-transform": $element.css("text-transform"), "letter-spacing": $element.css("letter-spacing") })
.appendTo($element.parent()),
width = tester.innerWidth();
tester.remove();
return width;
}
@andrewbranch
andrewbranch / avrdude.conf
Created February 19, 2018 05:03
Modified avrdude.conf for Adafruit Trinket
# $Id: avrdude.conf.in 1371 2016-02-15 20:15:07Z joerg_wunsch $ -*- text -*-
#
# AVRDUDE Configuration File
#
# This file contains configuration data used by AVRDUDE which describes
# the programming hardware pinouts and also provides part definitions.
# AVRDUDE's "-C" command line option specifies the location of the
# configuration file. The "-c" option names the programmer configuration
# which must match one of the entry's "id" parameter. The "-p" option
# identifies which part AVRDUDE is going to be programming and must match
@andrewbranch
andrewbranch / select2-override.css
Last active October 16, 2017 14:04
Flat styling of select2.
.select2-container .select2-choice {
height: 34px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
background-color: #fff;
background-image: none;
background: #fff;
}
@andrewbranch
andrewbranch / transpose-array-test.js
Created February 5, 2016 20:54
#algorithm challenge: more elegant way to do this
import { describe, it, beforeEach } from 'mocha';
import assert from 'assert';
import transposeArray from './transpose-array';
describe('transpose-array', () => {
let array;
beforeEach(() => array = [0, 1, 2, 3, 4, 5]);
it('works for downward transpositions', () => {
let result = transposeArray(array, 4, 2);
@andrewbranch
andrewbranch / fixBootstrapModalScrollbar.js
Last active December 31, 2015 07:09
One-up Bootstrap 3.0.0–3.0.3’s method of accounting for scrollbar width when modal is open.
// This function courtesy of lostsource: http://stackoverflow.com/questions/13382516
function getScrollbarWidth() {
var outer = document.createElement("div");
outer.style.visibility = "hidden";
outer.style.width = "100px";
document.body.appendChild(outer);
var widthNoScroll = outer.offsetWidth;
outer.style.overflow = "scroll";
var inner = document.createElement("div");
inner.style.width = "100%";
@andrewbranch
andrewbranch / KSSBluetoothController.h
Last active December 28, 2015 17:49
SwitchaBLE Light State characteristic write codes
typedef NS_OPTIONS(NSInteger, LightState) {
LightStateOff = 0,
LightStateOn = 1 << 0,
LightStateToggle = 1 << 1,
LightStatePulse = 1 << 2,
LightStateStrobe = 1 << 3
};
@andrewbranch
andrewbranch / ExampleView.aspx
Created September 10, 2013 16:44
HtmlHelper to generate JavaScript object from C# object
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<%= Html.WriteToJavaScript(Model, "window.model") %>
</asp:Content>