Skip to content

Instantly share code, notes, and snippets.

View aaronpowell's full-sized avatar
😶‍🌫️

Aaron Powell aaronpowell

😶‍🌫️
View GitHub Profile
@aaronpowell
aaronpowell / Simple JavaScript console
Created November 10, 2010 01:19
A basic JavaScript console window for browsers that don't support the console object
if (!window.console) {
window.onload = function() {
var txt = document.createElement('textarea');
txt.style.position = 'absolute';
txt.style.top = '0px';
txt.style.left = '0px';
txt.style.height = '800px';
txt.style.width = '500px';
txt.id = 'console';
document.body.appendChild(txt);
public class Foo : IEquatable<Foo>
{
readonly int bar;
public Foo(int bar)
{
this.bar = bar;
}
public override bool Equals(object obj)
public class Foo : IEquatable<Foo>
{
readonly int bar;
public Foo(int bar)
{
this.bar = bar;
}
public override bool Equals(object obj)
var dict = new Dictionary<string, int> {
{ "John", 3 },
{ "Mary", 4 }
};
var flattened = dict.Select(x =>
Enumerable.Range(0, x.Value).Select(_ => x.Key)
)
.SelectMany(x => x);
@aaronpowell
aaronpowell / StronglyTypeAnonymous.cs
Created December 3, 2010 02:52
Makes an anonymous type implement an interface
//uses ClaySharp: http://clay.codeplex.com
//add the following usings
//using ClaySharp;
//using ClaySharp.Behaviors;
void Main()
{
var foo = TypeMe<IFoo>(new { Id = 1, Name = "Aaron" });
Console.WriteLine(foo.Id);
Console.WriteLine(foo.Name);
<!doctype html>
<html>
<head>
<title>Loader</title>
<script type="text/javascript">
//assume this is in an external file, so we do an external here
var loader = (function() {
var scripts = [];
var ret = {
@aaronpowell
aaronpowell / loader.js
Created January 28, 2011 04:33
A simple JavaScript library for lazy loading JavaScript files
var loader = (function() {
var scripts = [];
var dw = function(s) {
document.write(s);
};
var ret = {
add: function(src) {
if(!scripts.indexOf(src)) {
scripts.push(src);
}
@aaronpowell
aaronpowell / blinky.js
Created February 9, 2011 10:02
How to implement blink with jQuery
(function($) {
$.fn.blinky = function(args) {
var opts = { frequency: 1e3, count: -1 };
args = $.extend(true, opts, args);
var i = 0;
var that = this;
var dfd = $.Deferred();
function go() {
if(that.length == 0) {
return dfd.reject();
@aaronpowell
aaronpowell / marquee.js
Created February 10, 2011 11:54
How to implement marquee with jQuery
(function($) {
$.fn.textWidth = function(){
var calc = '<span style="display:none">' + $(this).text() + '</span>';
$('body').append(calc);
var width = $('body').find('span:last').width();
$('body').find('span:last').remove();
return width;
};
$.fn.marquee = function(args) {
var s = "asd";
switch(true) {
case true:
if(s == "dsa") {
goto case false;
}
s = "dsa";
goto case true;