Skip to content

Instantly share code, notes, and snippets.

@bazzooka
bazzooka / getUnionTypeFromStringArray.ts
Last active January 27, 2022 23:20
Snippets Typescript
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"
@bazzooka
bazzooka / backblaze.js
Created August 30, 2021 10:09
Authorize Cloudflare to access Backblaze private buckets
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);
@bazzooka
bazzooka / Queue.js
Created March 30, 2016 11:53
Javacript simple queue with no performance consideration
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);
}
@bazzooka
bazzooka / Mouse experience.markdown
Created August 10, 2015 10:54
Mouse experience
@bazzooka
bazzooka / README.md
Created July 18, 2015 20:08
Add node program at Ubuntu startup

Installation

  • 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:

@bazzooka
bazzooka / waitForWIFI.bat
Created April 29, 2015 14:42
Script wait for wifi
@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
@bazzooka
bazzooka / gist:e7766a4187dc5b7a4d78
Created July 17, 2014 07:57
Make an history.go(+1), history.go(-1) to test performance
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)
@bazzooka
bazzooka / RandomRange
Created November 9, 2013 11:58
Random number in range
function randomRange(min, max){
return min + Math.random()*(max-min);
}
@bazzooka
bazzooka / revealSizes.js
Last active December 25, 2015 04:09
Replace each images of the document with colored block. Each block contain it's size. Usefull to work without images but with blocks sizes
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);
});