Skip to content

Instantly share code, notes, and snippets.

import {fileTypeFromStream} from 'file-type';
const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
const response = await fetch(url);
const fileType = await fileTypeFromStream(response.body);
console.log(fileType);
//=> {ext: 'jpg', mime: 'image/jpeg'}
if (typeof JSON.decycle !== "function") {
JSON.decycle = function decycle(object, replacer) {
"use strict";
var objects = new WeakMap(); // object to path mappings
return (function derez(value, path) {
var old_path;
@piemme
piemme / mongo_search_and_replace.js
Created March 9, 2018 11:49 — forked from rajiteh/mongo_search_and_replace.js
Recursively search and replace a string value across all collections in a mongodb database.
/*
Recursively traverses all collections and objects/arrays contained within documents replacing every
instance of 'find' with 'replace'.
mongo <db_name> mongo_search_and_replace.js
*/
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
@piemme
piemme / nohup-output-to-file.sh
Created February 5, 2018 17:43 — forked from umidjons/nohup-output-to-file.sh
Redirect nohup output to a file
# redirect output and errors into file output.log:
nohup some_command > output.log 2>&1&
# abbreviated syntax for bash version >= ver.4:
nohup some_command &> output.log
@piemme
piemme / README-Template.md
Last active August 27, 2018 16:07 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

Linux Graphics

Display Server Communication Protocol ("X protocol")

It encodes things such as graphic primitives, images, pointer motion, and key presses.

  • X11 (X Window System)
  • Wayland

Display Server ("X server")

Coordina I/O dei client ("xclient") da e verso il resto del sistema operativo e l'hardware. Gira all'interno del Kernel.

@piemme
piemme / mqtt.md
Last active December 18, 2017 18:51
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Apology extends JFrame {
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable() {
public void run() {
new Apology();