This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const roles = ['read', 'write', 'readAndWrite'] as const; | |
type Roles = typeof roles[number]; | |
// equals to this | |
// type Roles = "read" | "write" | "readAndWrite" | |
// or even like this | |
type RolesInCapital = Capitalize<typeof roles[number]>; | |
// equals to this | |
// type RolesInCapital = "Read" | "Write" | "ReadAndWrite" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener("fetch", (event) => { | |
event.respondWith( | |
handleRequest(event.request).catch( | |
(err) => new Response(err.stack, { status: 500 }) | |
) | |
); | |
}); | |
async function handleRequest(request) { | |
const { pathname } = new URL(request.url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Queue = function(size){ | |
this.list = new Array(size || 10); | |
return this; | |
} | |
Queue.prototype.enqueue = function(elem){ | |
this.list.shift(); // remove first element | |
this.list.push(elem); | |
} |
- Install forever with global option
sudo npm install -g forever
Making your forever app launch at boot using Ubuntu If you've installed forever and Node.js system-wide (so that they are located somewhere in $PATH), you can have your app started by forever at system-boot using Ubuntu's upstart. All you need to do is create a file named something like myapp.conf in /etc/init with the following contents:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo on | |
:waitloop | |
echo Waiting for wireless.... | |
Ping 127.0.0.1 -n 2 > nul | |
ipconfig |find /i "192.168.0.1" >nul | |
if errorlevel 1 goto waitloop | |
:connected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setTimeout(function(){ | |
console.log("Begin"); | |
var isOne = true; | |
var intervalTimer = setInterval(function () { | |
if (isOne) { | |
isOne = false; | |
history.go(+1); | |
} else { | |
isOne = true; | |
history.go(-1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function randomRange(min, max){ | |
return min + Math.random()*(max-min); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function revealSizes() { | |
$('img').each(function() { | |
var w = $(this).width(), h = $(this).height(), c = (Math.random() * 0xFFFFFF << 0).toString(16), classes = $(this).attr('class'); | |
var div = $('<div />').css({ | |
background: '#'+c, | |
fontSize: '200%' | |
}).width(w).height(h).addClass(classes).html(w+'x'+h); | |
$(this).replaceWith(div); | |
}); |