Skip to content

Instantly share code, notes, and snippets.

@queerviolet
queerviolet / angular-factory-demo.html
Created May 19, 2016 16:33
Angular Factories Example
<!doctype html>
<html ng-app=WeatherApp>
<head>
<title>You could just go outside</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="angular-factory-demo.js"></script>
</head>
<body ng-controller=CurrentWeatherCtrl>
<h1>The current temperature is {{ forecast.currently.apparentTemperature }}</h1>
<p>At {{ address }} ({{ forecast.latitude }}lat, {{ forecast.longitude }}lng)</p>
@queerviolet
queerviolet / index.html
Last active June 24, 2016 01:18
Sudoku skeleton
<!doctype html>
<html>
<head>
<title>Sudoku solver</title>
<style>
td {
border: 1px solid black;
margin: 0;
padding: 5px;
text-align: center;
@queerviolet
queerviolet / lazy.js
Last active February 9, 2025 15:32
Lazy
function lazy(promise) {
return new Proxy(lazy, {
get(target, prop, receiver) {
if (prop === lazy.promise) { return promise }
if (prop === 'catch' || prop === 'then') {
return ((...args) => promise[prop].apply(promise, args))
}
return lazy(promise.then(x => x[prop]))
},
@queerviolet
queerviolet / types.js
Last active February 9, 2025 15:32
Type Annotation Comments in JS
/**
* I like annotating my functions with comments that contain type annotations.
* The annotation syntax I use is, obviously, not an actual language, but it's
* strict enough to be one. Perhaps some day I'll write a yet another type flow tool
* to check these things!
*
* The syntax is a mishmash of Swift and JS destructuring expressions.
**/
/***** Basic format *****/
@queerviolet
queerviolet / todo.jsx
Last active January 26, 2023 07:56
Component injection in React
const React = require('react')
const List = ({
items,
Item = Todo.Item // Components recieve any components they depend on via props.
// The default assignment keeps our public interface clean.
}) => <ul>{items.map((item, index) => <Item key={index}>{item}</Item>)}</ul>
const Item = ({
@queerviolet
queerviolet / index.html
Created December 7, 2016 18:21
Hiring Day Playlist
<!doctype html>
<html>
<head>
<style>
html, body {
width: 100%; height: 100%; margin: 0; padding: 0;
background: black url('grace-hopper-fullstack-hiring-day-clean.webp');
background-size: contain;
background-position: center center;
background-repeat: no-repeat;
@queerviolet
queerviolet / Code.gs
Created April 5, 2017 02:22
Send sheet as email
// Load a menu item called "Project Admin" with a submenu item called "Send Status"
// Running this, sends the currently open sheet, as a PDF attachment
function onOpen() {
SpreadsheetApp.getActiveSpreadsheet().addMenu('Send sheet', [
{name: 'As email', functionName: 'send'}
]);
}
function getSheetAs(sheet, format) {
@queerviolet
queerviolet / .gitignore
Last active February 9, 2025 15:31
A little calculator
node_modules
@queerviolet
queerviolet / happy-numbers.js
Last active February 9, 2025 15:30
Floyd's cycle finder applied to happy numbers, in JS.
/**
* Exports an Object like {1: 1, 7: 7, 10: 10, ...},
* containing happy numbers up to 1000.
*
* This makes it easy for the test to check whether a given
* number is happy.
*/
module.exports = Object.assign(
...[
1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100, 103, 109, 129, 130, 133, 139, 167, 176, 188, 190, 192, 193, 203, 208, 219, 226, 230, 236, 239, 262, 263, 280, 291, 293, 301, 302, 310, 313, 319, 320, 326, 329, 331, 338, 356, 362, 365, 367, 368, 376, 379, 383, 386, 391, 392, 397, 404, 409, 440, 446, 464, 469, 478, 487, 490, 496, 536, 556, 563, 565, 566, 608, 617, 622, 623, 632, 635, 637, 638, 644, 649, 653, 655, 656, 665, 671, 673, 680, 683, 694, 700, 709, 716, 736, 739, 748, 761, 763, 784, 790, 793, 802, 806, 818, 820, 833, 836, 847, 860, 863, 874, 881, 888, 899, 901, 904, 907, 910, 912, 913, 921, 923, 931, 932, 937, 940, 946, 964, 970, 973, 989, 998, 1000
@queerviolet
queerviolet / form.jsx
Last active March 2, 2018 04:05
Select which component to render
const Beer = () => <div>
<input name='$$abv' />
</div>
const Wine = () => <div>
<input name='$$vintage' />
<input name='$$appellation' />
</div>
class Form extends React.Component {