Skip to content

Instantly share code, notes, and snippets.

View richardTowers's full-sized avatar

Richard Towers richardTowers

View GitHub Profile
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../paper-calculator/paper-calculator.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
./|,,/|
< o o)
<\ ( |
<\\ |\ |
<\\\ |(__)
<\\\\ |
N1C4AA
N1C4AB
N1C4AD
N1C4AE
N1C4AF
N1C4AH
N1C4AJ
N1C4AL
N1C4AN
N1C4AP
@richardTowers
richardTowers / LinkedListVsList.cs
Last active December 18, 2015 17:09
A comparison of LinkedList performance against List performance. Inserting elements at the start of the list.
void Main()
{
const int maxHits = 100*1000;
var list = new List<Tuple<int, TimeSpan, TimeSpan>>();
for(var i = 10; i < maxHits; i *= 2)
{
var output = Test(i);
list.Add(Tuple.Create(i, output.Item1, output.Item2));
}
@richardTowers
richardTowers / gist:5207061
Last active December 15, 2015 05:09
Quick demo of pitfalls of `this` in JavaScript
<!doctype html>
<html>
<head>
<title>this</title>
</head>
<body>
<div><a id="broken" href="#">Incorrectly bound click</a></div>
<div><a id="working" href="#">Correctly bound click</a></div>
<div><a id="working2" href="#">Also correctly bound click</a></div>
<script>
@richardTowers
richardTowers / MozartNotes.rb
Created February 1, 2013 22:50
Reads a music XML file and counts the notes that are C5.
require "rexml/document"
include REXML
file = File.new( "String Quartet No. 3 in G Major, K. 156.xml" )
doc = Document.new file
notes = XPath.match( doc, "//note/pitch[step='C' and octave='5' and not(alter)]" )
puts notes.length
@richardTowers
richardTowers / var.js
Created January 24, 2013 20:06
Eplanation of `var` in loops in javascript.
// Normal variable:
var x = 7;
// Used like:
console.log(x); // => 7
// Variable declared in a loop
for(var i = 0; i < 3; i++) {
// Used like:
console.log(i); // => 0,1,2
void Main()
{
const int listSize = 1000;
const int sampleSize = 10000;
var sortedList = Enumerable.Range(0,listSize).ToList();
var unsortedList = new List<int>(sortedList);
var sortedCount = 0;
sortedList.Sort((l,r) => {sortedCount++; return l - r;});