Skip to content

Instantly share code, notes, and snippets.

View justingreenberg's full-sized avatar

justin justingreenberg

View GitHub Profile
////////////////////////////////////////////////////////////////////////////////
// Create a directory called "pages" next to
// this file, put markdown files in there, and
// then run:
//
// ```
// $ node build.mjs
// ```
//
// Then deploy the "build" directory somewhere.
@nileshtrivedi
nileshtrivedi / home-server.md
Last active June 1, 2024 00:11
Home Server setup: Raspberry PI on Internet via reverse SSH tunnel

Raspberry Pi on Internet via reverse SSH tunnel

HackerNews discussed this with many alternative solutions: https://news.ycombinator.com/item?id=24893615

I already have my own domain name: mydomain.com. I wanted to be able to run some webapps on my Raspberry Pi 4B running perpetually at home in headless mode (just needs 5W power and wireless internet). I wanted to be able to access these apps from public Internet. Dynamic DNS wasn't an option because my ISP blocks all incoming traffic. ngrok would work but the free plan is too restrictive.

I bought a cheap 2GB RAM, 20GB disk VM + a 25GB volume on Hetzner for about 4 EUR/month. Hetzner gave me a static IP for it. I haven't purchased a floating IP yet.

class GitHubStrategy extends OAuthStrategy {
async getProfile (authResult) {
const accessToken = authResult.access_token;
// get private email
let { data } = await axios.get('https://api.github.com/user/emails', {
headers: { authorization: `Bearer ${accessToken}` }
});
// get user data
@tanaikech
tanaikech / submit.md
Last active January 5, 2025 06:09
Simple Script of Resumable Upload with Google Drive API for Node.js

Simple Script of Resumable Upload with Google Drive API for Node.js

This is a simple sample script for achieving the resumable upload to Google Drive using Node.js. In order to achieve the resumable upload, at first, it is required to retrieve the location, which is the endpoint of upload. The location is included in the response headers. After the location was retrieved, the file can be uploaded to the location URL.

In this sample, a PNG file is uploaded with the resumable upload using a single chunk.

Sample script

Before you use this, please set the variables.

@ferrerojosh
ferrerojosh / keycloak.provider.ts
Last active July 10, 2023 20:03
Keycloak v9.0.0 NestJS Resource Guard
import { FactoryProvider, Logger } from '@nestjs/common';
import Keycloak from 'keycloak-connect';
export const KEYCLOAK_INSTANCE = 'KEYCLOAK_INSTANCE';
export const keycloakProvider: FactoryProvider = {
provide: KEYCLOAK_INSTANCE,
useFactory: () => {
const keycloakConfig: any = {
realm: '',
@OnnoGabriel
OnnoGabriel / login-attempt-limiter.js
Last active April 30, 2021 06:13
Login Attempt Limiter for Feathers
/**
* Login Attempt Limiter Hook for Feathers (https://feathersjs.com/)
*
* Limits the login attempts by recording the number of failed logins
* and the datetime of the last login attempt to the user data.
*
* 1. Extend your user model by two fields:
* loginAttempts: {
* type: DataTypes.INTEGER,
* defaultValue: 0
@markmichon
markmichon / CircuitBreaker.js
Last active July 23, 2021 21:13
Basic CircuitBreaker Node
class CircuitBreaker {
constructor(request) {
this.request = request
this.state = "CLOSED"
this.failureThreshold = 3
this.failureCount = 0
this.successThreshold = 2
this.successCount = 0
this.timeout = 6000
this.nextAttempt = Date.now()
// Pass in the callback that we want to throttle and the delay between throttled events
const throttle = (callback, delay) => {
// Create a closure around these variables.
// They will be shared among all events handled by the throttle.
let throttleTimeout = null;
let storedEvent = null;
// This is the function that will handle events and throttle callbacks when the throttle is active.
const throttledEventHandler = event => {
// Update the stored event every iteration
@slorber
slorber / react-navigation-tree.jsx
Last active August 13, 2022 19:17
react-navigation-tree.jsx
const App = createAppContainer(
createStack({
LoggedSwitch: createSwitch({
// When user is authenticated
LoggedIn: createStack({
// The logged in root is generally a tab or drawer navigator
LoggedInRoot: createTabsOrDrawer({
import React from "react";
import { Link } from "react-router-dom";
export function createResource(getPromise) {
let cache = {};
let inflight = {};
let errors = {};
function load(key) {
inflight[key] = getPromise(key)