Skip to content

Instantly share code, notes, and snippets.

@Dykam
Dykam / README.md
Created February 28, 2012 19:12 — forked from Zegnat/README.md
Fixing your skip links. [JS]

Fixing your skip links.

Read Damon Muma on this. He proposes the following jQuery solution (inspired by Thompson, fixed by me):

// Apply focus properly when accessing internal links with keyboard in WebKit browsers.
$("a[href^='#']").not("a[href='#']").click(function() {
   $("#"+$(this).attr("href").slice(1)+"").focus();
});
@Dykam
Dykam / Source.js
Created January 3, 2012 00:03
Script to remove all apps from https://www.facebook.com/settings?tab=applications Compressed url form below, ready for pasting.
// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level ADVANCED_OPTIMIZATIONS
// ==/ClosureCompiler==
(function () {
var el = document.createElement('div'),
b = document.getElementsByTagName('body')[0];
otherlib = false, msg = '';
el.style.position = 'fixed';
@Dykam
Dykam / Fibonacci
Created September 25, 2011 12:40
Messing around with CoffeeScript
fib = (n) ->
next = 1
current: 0
movenext: ->
if n-- is 0
@movenext = -> false
return false
[@current, next] = [next, @current + next]
true
@Dykam
Dykam / gist:1193595
Created September 4, 2011 22:06
[SpoutCraft] Proposal for centralized input

#The problem Currently plugins are supposed to listen to input using the InputManager. There are three issues to this.

  • Binding conflicts. Plugins might use the same key. This is mostly an issue with the tab and ctrl keys.
  • Rebinding confusion. Each plugin, if it is configurable, defines its own way of redefining keybindings. This is confusing.
  • By default all presses are mapped, including when for example chat is open.

#The solution Let plugins define keybindings by means of a simple string as key. Conflicts between plugins are solved because the plugin is part of the key. Client side the user can set the keybinding to an actual key, which is defaulted to a configurable default. The client side part is done by SpoutCraft, possibly by modifying the keybindings screen to add plugin keybindings. Here's the code the plugin has to use:

class A
foo: "bar"
class B extends A
zoo: "zar"
alert (new B).foo # "bar"
alert (new B).zoo # "zar"
browser.test '/',
test: ->
@clickAndWait link: 'Barnwood Dining Tables'
@assertTitle 'Old Wood Coffee Tables | Solid | Dining | Rustic | Round | Rectangle'
@assertElementPresent '//head/meta[@name="keywords" and @content="Old Wood Coffee Tables, Solid Old Wood Dining Tables, Rustic Dining Table"]'
@assertElementPresent '//head/meta[@name="description" and @content="Old Wood Coffee Tables, Solid Old Wood Dining Tables, Rustic Dining Table – Lake and Mountain Home for the best Custom, Dark, Natural, Round, Farm, Solid Pine, Trestle & Bench Dining Tables, Country Style, Cottage, Custom Old Wood Coffee Tables and more."]'
#Wood Chairs, Barnwood Benches & Stools Category
@clickAndWait link: 'Lake And Mountain Home'
@clickAndWait link: 'Wood Chairs, Barnwood Benches & Stools'
@assertTitle 'Casual Dining Chairs | Benches | Stools | Reclaimed | Wooden'
$ ->
your
code
here
divide = function(n) {
var sqrtN = Math.floor(Math.sqrt(n));
var i = 1;
while(i++ < sqrtN)
if(n % i == 0)
return [i].concat(divide(n / i));
return [n];
}
class Range
constructor: (@ranges...) ->
@rangePoints = (Array.prototype.concat (Range.fixRanges @ranges)...).sort()
@ranges = ([start, @rangePoints[i + 1]] for start, i in @rangePoints by 2)
intersect: (ranges...) ->
new Range @rangePoints.concat (Range.fixRanges ranges)...
@fixRanges: (ranges) -> range.rangePoints or range for range in ranges
prop = (obj, props) ->
for prop, getset of props
if getset.get
obj.__defineGetter__ prop, -> getset.get.apply obj, arguments
if getset.set
obj.__defineSetter__ prop, -> getset.set.apply obj, arguments
class SomeCar
constructor: ->
_doors = 4