Skip to content

Instantly share code, notes, and snippets.

View marcio199226's full-sized avatar
🎯
Focusing

oskar marcio199226

🎯
Focusing
View GitHub Profile
@nesimtunc
nesimtunc / ImageController.js
Last active July 21, 2024 03:03
Minio Server - NodeJS - File Upload & Photo Showing Example
const formidable = require('formidable');
const fs = require('fs');
var Minio = require('minio');
let minioClient = new Minio.Client({
endPoint: config.MINIO.ENDPOINT,
port: config.MINIO.PORT,
accessKey: config.MINIO.ACCESS_KEY,

The default format of keys was changed in OpenSSL 1.0. From OpenSSL 1.0 change log:

Make PKCS#8 the default write format for private keys, replacing the traditional format. This form is standardised, more secure and doesn't include an implicit MD5 dependency. [Steve Henson]

Good explanations of the difference between the two formats: https://tls.mbed.org/kb/cryptography/asn1-key-structures-in-der-and-pem

Converting RSA private key:

@mholt
mholt / macapp.go
Last active May 1, 2025 04:32
Distribute your Go program (or any single binary) as a native macOS application
// Package main is a sample macOS-app-bundling program to demonstrate how to
// automate the process described in this tutorial:
//
// https://medium.com/@mattholt/packaging-a-go-application-for-macos-f7084b00f6b5
//
// Bundling the .app is the first thing it does, and creating the DMG is the
// second. Making the DMG is optional, and is only done if you provide
// the template DMG file, which you have to create beforehand.
//
// Example use:
@pianosnake
pianosnake / bounding-box-from-lat-lng-zoom-img-size.js
Last active January 20, 2025 20:18
Get a bounding box from latitude, longitude, zoom level and image size. Useful for getting the bounding box of a static map generated with only those variables.
const EARTH_CIR_METERS = 40075016.686;
const degreesPerMeter = 360 / EARTH_CIR_METERS;
function toRadians(degrees) {
return degrees * Math.PI / 180;
};
function latLngToBounds(lat, lng, zoom, width, height){
const metersPerPixelEW = EARTH_CIR_METERS / Math.pow(2, zoom + 8);
const metersPerPixelNS = EARTH_CIR_METERS / Math.pow(2, zoom + 8) * Math.cos(toRadians(lat));
@sechel
sechel / @ BroadcastChannel Polyfill.md
Created September 13, 2018 15:47
BroadcastChannel Polyfill

BroadcastChannel Polyfill

BroadcastChannel is a new communication API proposed in the HTML Standard but not yet widely implemented. It allows messages to be sent to all other BroadcastChannel instances sharing the same channel name within the same browsing context and origin.

var bc = new BroadcastChannel('name');

bc.postMessage(payload);
@kig
kig / mic.js
Created October 6, 2018 07:25
Microphone input to MP3
// Uses getUserMedia to record audio from microphone, compresses it to mp3, and throws it away.
// You should change the last step to e.g. pushing the audio to a server over a WebSocket.
// This script uses lame.js for mp3 encoding
// https://github.com/zhuker/lamejs
var audioDataCallback = function(encodedData, originalData) {
console.log("Encoded " + encodedData.byteLength + " bytes. Original: " + originalData.byteLength);
};
@angeal185
angeal185 / chacha20-poly1305.js
Created May 6, 2019 13:05
nodejs chacha20-poly1305 encrypt decrypt example
const crypto = require('crypto');
let key = crypto.randomBytes(32),
text = 'test';
function encChaPoly(key, data, cb){
try {
let iv = crypto.randomBytes(12),
cipher = crypto.createCipheriv('chacha20-poly1305', key, iv, {
authTagLength: 16
@Jonarod
Jonarod / blob_conversions_util.js
Created December 7, 2019 04:56
Javascript utility to convert Blob to Base64, ImageData or ObjectUrl back and forth. Tree shakeable and promise based.
const BlobToBase64 = function(blob){
let blobUrl = URL.createObjectURL(blob);
return new Promise((resolve, reject) => {
let img = new Image();
img.onload = () => resolve(img);
img.onerror = err => reject(err);
img.src = blobUrl;
}).then(img => {
URL.revokeObjectURL(blobUrl);
@send2moran
send2moran / debounceMutationObserver.js
Created April 26, 2020 16:03
debounce MutationObserver
const debounce = (func, delay) => {
let debounceTimer;
return function() {
const context = this;
const args = arguments;
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => func.apply(context, args), delay);
};
};
let summery = { addded: [], removed: [] };
@tristanidoux
tristanidoux / @ngtools+webpack+9.1.10.patch
Last active July 25, 2024 12:08
Enable ifdef-loader preprocessing with webpack 7+
Since @ngtools/webpack doesn't support preprocess chain loader, see (here)[https://github.com/nippur72/ifdef-loader/issues/4].
We use process.env to pass the ifdef loader options and patch the compiler (webpack) to read the env and parse the files.
We use a prefix 'IFDEF_' to filter the environment variables.
This is more a fix than anything else for now. A better fix would have been a PR to enable webpack to use any preprocessor
but I don't have the time right now.
diff --git a/node_modules/@ngtools/webpack/src/compiler_host.js b/node_modules/@ngtools/webpack/src/compiler_host.js
index 58d942c..a7db0be 100644
--- a/node_modules/@ngtools/webpack/src/compiler_host.js