Skip to content

Instantly share code, notes, and snippets.

@dawnerd
dawnerd / Fibonacci.html
Created November 13, 2010 21:55
Outputs fibonacci numbers in JS
<html>
<head>
<title>fibonacci sequence</title>
</head>
<body>
<p>This will output a ton of numbers and might take a while.</p>
<div id="output"></div>
<script>
var o = '0, 1, ', f = 0, s = 1, n = 1, c = 1000;
@dawnerd
dawnerd / Super short countdown.js
Last active September 24, 2015 05:57
Shortest countdown function ever.
setInterval(function() {
console.log([s = [86400000, 3600000, 60000, 1000]][0].map(function(t) {
return ("0" + [(t===s[0] && (remaining = (future - ~~(+new Date()/1000))*1000)), left = ~~(remaining/t), remaining -= left*t][1]).slice(-2);
}).join(':'));
}, [1000, future = +new Date()/1000 + 100000][0]);
var letters = "apples".split("").sort().join(""), words = ["pale", "ales", "ape", "grape", "pape", "pppp"];
document.writeln("Matching words to: " + letters);
for(var i = 0, c = words.length; i < c; i++) {
var word = words[i].split("").sort().join(""), status = true, usedChars = [];
for(var ii = 0, cc = word.length-1; ii < cc; ii++) var lidx = letters.indexOf(word[ii], ii), idx = usedChars.indexOf(lidx), status = ((idx == -1 && lidx != -1) ? new Boolean(usedChars.push(lidx)) : false);
document.writeln(words[i] + " " + status);
}
@dawnerd
dawnerd / fb_cargo.js
Created March 4, 2011 00:12
Plane cargo challenge
var items = {
'LJS93K': {
pounds: 1300,
cost: 10500
},
'J38ZZ9': {
pounds: 700,
cost: 4750
},
'HJ394L': {
var f = 0, s = 1, n = 1, total = 0;
while(n < 4000000) {
n = (f+s);
f = s;
s = n;
if(!(n % 2)) total += n;
}
print(total);
@dawnerd
dawnerd / musicget.js
Created July 26, 2011 06:42
Random script to grab mp3s from youtube-mp3
var links = ["TkPbJIlEXow",
"Z4nAUPw8j5s",
"H5MtQA5dvrU",
"ouNvc6GRwUg",
"0VI4HV0pX-o",
"h-x0y3o1UwA",
"Z4nAUPw8j5s",
"MOzQ4Bs916I",
"JByDbPn6A1o",
"rf2kMnnNROc",
@dawnerd
dawnerd / nodemasher.js
Created August 4, 2011 23:15
node masher
module.exports = function(app) {
app.helpers({
getJS: function(key) {
var output = '';
app.configure('development', function(){
try {
var files = app.set('masher_config').JAVASCRIPT[key];
for(var i = 0, c = files.length; i < c; i++) {
var file = files[i].replace('./public', '');
output += '<script src="'+file+'"></script>';
@dawnerd
dawnerd / app.js
Created September 12, 2011 06:05
basic-auth example
var express = require('express'),
app = module.exports = express.createServer();
//Basic-Auth config
var auth = require('basic-auth')({
name: 'Test Auth',
accounts: [
'test:password',
'test2:password2'
]
@dawnerd
dawnerd / lolumad.js
Created September 19, 2011 21:04
Trollify JS
!function(){
//These can be anything you want ;)
var images = [
'http://28.media.tumblr.com/ei729ojaFm9ickfnHLmkACuuo1_400.jpg',
'http://26.media.tumblr.com/ei729ojaFm9ic7489TiIUBvvo1_400.jpg',
'http://26.media.tumblr.com/ei729ojaFm9iasuebHQjetZro1_400.jpg',
'http://28.media.tumblr.com/ei729ojaFm9i5f8mO0DHWAu3o1_400.jpg'
]
//let the trolling begin
@dawnerd
dawnerd / fidelway.js
Created October 21, 2011 23:46
Enterprise JS
var NumberInput = Fidel.ViewController.extend({
init: function() {
this.el.bind('keyup', this.proxy(this.changeValue));
},
changeValue: function() {
var value = ~~(this.el.val());
this.el.val(value);
this.trigger('valueChanged', [value]);
}
});