Skip to content

Instantly share code, notes, and snippets.

View nor1c's full-sized avatar
🔥
https://github.com/sponsors/uuppyy

Noric F. nor1c

🔥
https://github.com/sponsors/uuppyy
View GitHub Profile
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Firebase.Extensions;
using Google;
using UnityEngine;
using UnityEngine.UI;
public class FirebaseManager : MonoBehaviour
{
@nor1c
nor1c / middle-backend-programmer-test.md
Created March 22, 2024 07:09 — forked from RofieSagara/middle-backend-programmer-test.md
Middle Backend Programmer - Job Test

Task Description: Your task is to create a Golang backend service with HTTP routes for image processing. The service should provide the following functionalities:

  1. Convert image files from PNG to JPEG.
  2. Resize images according to specified dimensions.
  3. Compress images to reduce file size while maintaining reasonable quality.

Instructions:

  1. Create a Golang project with necessary dependencies to implement the image processing functionalities.
@nor1c
nor1c / simple-dependency-inversion-in-typescript.ts
Created December 18, 2022 14:04
Simple Dependency Inversion
// https://www.typescriptlang.org/play?#code/MYewdgziA2CmB0w4EMBOAKAlAKGwSzABdZUAzZYWAAgEkAFZATwFtYi7URKIpUqBvbFWFVmyANawGLNoXR5izAFxUIhVAQDmAGioBXMAo55KKsHuYAjEroCOhRmYvXUmFQDcQeACbYAvrgA9IFUAMrqeAAO1NKsRFQAMiCaJthIyDxhEdECQiKRGu7IxFSWeowkAHLIrCpqGmCauCJUoJDqesCEIBhlFajVtaoRjZi5LS2EABZ4EPB9VTXUALyl5YusecIBW1SRTPKKdSM6VN2EyNDGplTmViRjghMibVBw8NDJ6AAGACT801m83WAyWflKID0mimhCoyCo-wUsGY4OKew0lAR-3Ol2usD83xwLQCO3SmXCGmisVkHC4sB4PSoeGYkTgcUIEFo1PYnG4vHG+UKxWo9SisBUFLFzRe4HqnW6vRBg3Fwwamkeu0mMzmopyqzAsAA7llKbB0AtQawiSIdi0xJJuXIkcpVVpdAYjBiVXcXHYHE57q4Bc9ATrsgh9oxDsi-YwqAAqfSGQh463bfxBELSfbQKiOxLJVJkznZy7B9F4IolC3K45q6XCV4dLo9c1KpZ1rQa57CUPA-rKqirGtLXa2-IHZ2dxq6HFXL0BlzdnuvGAIT6aH7Y7X9jb4iFQmFwhH8Z2o2EFEzUX7YkAXedXglpqgk3DFvNMHOO2l8xnM1nIrInL0Ew7I-vS-JPIKlbCq60QSuGDatLKzYKm2A4dq6ozllqQK6istxGiaYroXuz7jsI9pSKBsjRi6oozkmnpXouNhUPYji3M4Dw4SIfb4fAkZ0bGCZMSmXrkRm2DBFQADyeh8OEPSwGk0AZJySmoNQUHCJeVbUJGYG8hBPQIaa37GQyfAAD4fowX40TydJWUhTaoPKraGTSlm8GZYoWc5-K2aWVyOeJgU9MuIY7l5Tm-nwqyxeF8VjkhkQKcAUwZLAABCeCSOgHGsUGOkTE2FaYqsAC
@nor1c
nor1c / error-handling-with-fetch.md
Created March 14, 2022 03:39 — forked from odewahn/error-handling-with-fetch.md
Processing errors with Fetch API

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
 })

Keybase proof

I hereby claim:

  • I am nor1c on github.
  • I am nor1c (https://keybase.io/nor1c) on keybase.
  • I have a public key ASCcjvNTNbt8GjXtUy0_GidyGBBiz2VLHFjlUSxs597nkgo

To claim this, I am signing this object:

Don't Re-use SftpClient Objects

Due to an issue with ECONNRESET error signals when connecting to Windows based SFTP servers, it is not possible to remove the error handler in the end() method. This means that if you re-use the SftpClient object for multiple connections e.g. calling connect(), then end(), then connect() etc, you run the risk of multiple error handlers being added to the SftpClient object. After 11 handlers have been added, Node will generate a possible memory leak warning.

To avoid this problem, don't re-use SftpClient objects. Generate a new SftpClient object for each connection. You can perform multiple actions with a single connection e.g. upload multiple files, download multiple files etc, but after you have called end(), you should not try to re-use the object with a further connect() call. Create a new object instead.

{
"editor.fontSize": 15,
// "editor.fontFamily": "Consolas, 'Courier New', monospace",
// "editor.fontFamily": "Consolas",
"editor.fontFamily": "Roboto Mono",
// "editor.fontFamily": "Ubuntu Mono",
"editor.fontWeight": "400",
"window.zoomLevel": 0,
"explorer.confirmDelete": false,
"atomKeymap.promptV3Features": true,

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@nor1c
nor1c / settings.json
Last active July 19, 2020 04:06
My VS Code Preset
{
"editor.fontSize": 14,
// "editor.fontFamily": "Consolas, 'Courier New', monospace",
// "editor.fontFamily": "Consolas",
"editor.fontFamily": "Roboto Mono",
// "editor.fontFamily": "Ubuntu Mono",
// "editor.fontWeight": "600",
"window.zoomLevel": 0,
"explorer.confirmDelete": false,
"atomKeymap.promptV3Features": true,
@nor1c
nor1c / saveas.js
Created September 9, 2019 09:35 — forked from wemersonjanuario/saveas.js
Ajax blob save as.. file download
var url = 'http://www.pdf995.com/samples/pdf.pdf';
var fileName = 'pdf.pdf';
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onprogress = function(pe) {
console.log('progress');
if (pe.lengthComputable) {
console.log((pe.loaded / pe.total) * 100);