Skip to content

Instantly share code, notes, and snippets.

process.on("unhandledRejection", function(reason, p) {
console.log(reason, p);
console.log("Rejection handled")
new Promise(function(resolve, reject) {
console.log("Second rejection")
reject(new Error("Foo"));
});
});
@adriancooney
adriancooney / App.js
Last active March 17, 2017 14:25
Redux in React.
import React, { Component } from 'react';
import Provider from "./Provider";
import Incrementer from "./Incrementer";
class App extends Provider {
state = { value: 0 };
render() {
const increment = this.dispatch.bind(this, { type: "INCREMENT" });
const decrement = this.dispatch.bind(this, { type: "DECREMENT" });
@adriancooney
adriancooney / dinosauras.js
Last active February 8, 2017 01:20
Cheat in Chrome's "No network connection" dinosaur game. Paste this in the console when you find yourself on the screen (or disconnect from the internet and attempt to load a page).
const update_ = Runner.instance_.update;
Runner.instance_.update = function() {
if(this.horizon.obstacles.length) {
const nearestObstacle = this.horizon.obstacles[0];
if(nearestObstacle.xPos < 115 && !this.tRex.jumping) {
if(nearestObstacle.yPos <= 50) {
this.tRex.setDuck(true);
setTimeout(this.tRex.setDuck.bind(this.tRex, false), 500);
} else {
this.tRex.startJump(this.currentSpeed);
src/data/auth.coffee-112- id: installationId)
src/data/auth.coffee-113- return new Promise (resolve, reject) ->
src/data/auth.coffee-114- projectsDLM.get cacheKey, (err, res) ->
src/data/auth.coffee-115- return reject(err) if err?
src/data/auth.coffee-116- return resolve res if res?
src/data/auth.coffee:117: currentTimestamp = Date.now().toString()
src/data/auth.coffee-118- projectsDLM.set cacheKey, currentTimestamp, (err, res) ->
src/data/auth.coffee-119- return reject(err) if err?
src/data/auth.coffee-120- resolve currentTimestamp
src/data/auth.coffee-121-
@adriancooney
adriancooney / 2014_2015_CH140_1_1_5.json
Created November 6, 2015 20:16
Exam PDF translated to JSON.
{
"section_a": {
"1": {
"i": {
"content": " Explain using examples why many hard RTS use a cyclic executive approach to scheduling whereas many soft RTS utilise a real-time operating system. [10] "
},
"ii": {
"content": " Using Antilock Braking Systems (ABS) as an example, distinguish between the sample rate and response time of a RTS. [10] "
},
"iii": {
@adriancooney
adriancooney / nw-js-cookies.js
Created July 23, 2015 17:25
Quick snippet to display cookie in NW.js (node-webkit) in a sweet console table.
require("nw.gui").Window.get().cookies.getAll({}, console.table.bind(console));
@adriancooney
adriancooney / loop-u-s-v.js
Created June 21, 2014 00:10
Javascript Proxy Madness
loop[0][2][20] = function(i) {
console.log(i);
};
// Output:
// 0
// 2
// 4
// 6
// 8
@adriancooney
adriancooney / newline.js
Created August 27, 2013 17:01
"Native" multiline Javascript strings (with some funky syntax)
var multiline = function(string) {
// Replace the "function() {/*\n" and "\n*/}" with nothing and bam, multiline strings
return string.toString().replace(/(^[^\n]*\n)|(\n\*\/\})/g, "");
};
console.log(multiline(function() {/*
Hello world!
I'm a multiline string!
Tada!
<body>
  <div>
		<header>
			<h1 id="title"><em><a href="/">Hello world!</a></em></h1>
		</header>
		<section>
			<ul>
				<li class="item"><a href="#">Navigation Item</a></li>
 <a href="#">Navigation Item</a>
@adriancooney
adriancooney / sudoku.js
Created April 20, 2012 21:13
Generate a sudoku game
var sudoku = [], iterationCount = 0;
function check(type, pos, num) {
var bool = false;
for(var i = 0; i < 9; i++) {
var tile = (type === 1) ? (pos * 9) + i : //row
(type === 2) ? (i * 9) + pos : null; //Column
(((((pos - (pos % 3))/3) * 3)) * 9) + ((((pos % 3) * 3)) + (i % 3)); //Quadrant