Skip to content

Instantly share code, notes, and snippets.

View dalmaer's full-sized avatar

Dion Almaer dalmaer

View GitHub Profile
// Assuming that the request to fetch the already written bytes has just
// taken place and xhr.result contains the response from the server.
var start = xhr.result.numWrittenBytes;
var length = file.size - start;
var chunk = file.slice(start, length);
var req = new XMLHttpRequest();
req.open('post', 'fnc.php?fnc=resume', true);
req.setRequestHeader("Cache-Control", "no-cache");
// snap cursor
if(distM < 30 && count > 50) {
count = 0;
$("#mouth").css({ "height":"", "-webkit-transform":"", "-moz-transform":"" });
$("body").css({ "cursor":"none" });
$('#wrapper').removeClass("hungry").addClass("eat");
playAudio("audio-snap");
status = "eat";
} else {
count++;
// Suboptimal, causes layout twice.
var newWidth = aDiv.offsetWidth + 10; // Read
aDiv.style.width = newWidth + 'px'; // Write
var newHeight = aDiv.offsetHeight + 10; // Read
aDiv.style.height = newHeight + 'px'; // Write
// Better, only one layout.
var newWidth = aDiv.offsetWidth + 10; // Read
var newHeight = aDiv.offsetHeight + 10; // Read
aDiv.style.width = newWidth + 'px'; // Write
Step(
// Loads two files in parallel
function loadStuff() {
fs.readFile(__filename, this.parallel());
fs.readFile("/etc/passwd", this.parallel());
},
// Show the result when done
function showStuff(err, code, users) {
if (err) throw err;
sys.puts(code);
// -- input
// simple call
fish = $.get! '/fish'
$("stomach").append fish
// another simple call with implied ()
ok = stomach.save!
meal.complete = ok
// -- output
if (window.matchMedia("(min-width: 400px)").matches) {
// The screen width is 400px or wider.
} else {
// The screen width is less than 400px.
}
function setup_for_width(mql) {
if (mql.matches) {
// The screen width is 400px or wider. Set up or change things
// appropriately.
} else {
// The screen width is less than 400px. Set up or change things
// appropriately.
}
}
.rtl ul {
text-align: left\9; /* IE8/9 */
*text-align: left; /* IE5/6/7 */
}
// create a test object
var obj = {a:1, get b() {return "b value"}, c: undefined};
obj.c = {back: obj}; // make a circular reference to obj
// create an introspection mirror on obj
var m = Mirrors.introspect(obj);
console.log(m); //output: "Object Introspection Mirror #0"
console.log(m.ownPropertyNames) ; //output: "a,b,c"
console.log(m.extensible); //output: true
// this equation took FOREVER to pinpoint through less than mathematical means of trial and error.
// Holy euclidian bullcrap, Batman! 1 - ratio, what is this nonsense?!
// A thanks to IdleT user Forbin for simplifying the equation for me further.
function parallax(containerClassRef, ratio){
$(containerClassRef).css({
left: Math.round( (1 - ratio) * ( cellWd / 2 + $(window).scrollLeft() ) )+'px'
});
}