Skip to content

Instantly share code, notes, and snippets.

View justingreenberg's full-sized avatar

justin justingreenberg

View GitHub Profile
@lizthegrey
lizthegrey / attributes.rb
Last active March 27, 2025 02:16
Hardening SSH with 2fa
default['sshd']['sshd_config']['AuthenticationMethods'] = 'publickey,keyboard-interactive:pam'
default['sshd']['sshd_config']['ChallengeResponseAuthentication'] = 'yes'
default['sshd']['sshd_config']['PasswordAuthentication'] = 'no'
@nzvtrk
nzvtrk / axiosInterceptor.js
Last active April 14, 2025 13:50
Axios create/recreate cookie session in node.js enviroment
/* Basic example of saving cookie using axios in node.js and session's recreation after expiration.
* We have to getting/saving cookie manually because WithCredential axios param use XHR and doesn't work in node.js
* Also, this example supports parallel request and send only one create session request.
* */
const BASE_URL = "https://google.com";
// Init instance of axios which works with BASE_URL
const axiosInstance = axios.create({ baseURL: BASE_URL });
@ryzokuken
ryzokuken / merkle.js
Last active July 30, 2022 15:57
TypeScript Merkle Tree Implementation
const hash = require('easy-crypto/hash');
class MerkleTreeNodeGeneric {
compare(node) {
return this.hash === node.hash;
}
}
class MerkleTreeChildNode extends MerkleTreeNodeGeneric {
constructor(data) {
@sbrichardson
sbrichardson / polar.js
Last active December 31, 2023 08:14
Connects to a nearby bluetooth heart rate monitor and logs the active heart rate at 1hz (once per second). Tested with a Polar H10 HR monitor using Google Chrome.
/*
Make sure you are wearing the hr monitor, as it typically
goes to sleep when inactive, not allowing you to connect to it.
Instructions
=============
1. Using Google Chrome, open the dev console and paste the below code.
2. A panel near the address bar will open, searching for nearby bluetooth (ble)
heart rate devices. Don't click away from the panel or Chrome will cancel the search.
@bvaughn
bvaughn / index.md
Last active February 25, 2025 15:56
Interaction tracing with React

This API was removed in React 17


Interaction tracing with React

React recently introduced an experimental profiler API. After discussing this API with several teams at Facebook, one common piece of feedback was that the performance information would be more useful if it could be associated with the events that caused the application to render (e.g. button click, XHR response). Tracing these events (or "interactions") would enable more powerful tooling to be built around the timing information, capable of answering questions like "What caused this really slow commit?" or "How long does it typically take for this interaction to update the DOM?".

With version 16.4.3, React added experimental support for this tracing by way of a new NPM package, scheduler. However the public API for this package is not yet finalized and will likely change with upcoming minor releases, so it should be used with caution.

@funkjunky
funkjunky / chunkedFileStreaming.js
Created July 28, 2018 20:03
This is some fun code I had written to handle uploading any number of files of any size, using compression and streaming. (Note: Node doesn't require you convert a stream to an iterator)
export const webFileToResumableDescriptor = (file, uploadId) => async function(chunkSize) {
uploadId = uploadId || file.name;
return {
bytesCount: file.size,
uploadId: uploadId,
filename: file.name,
generator: async function*() {
let chunkIndex = 0;
// While starting byte is less than the file size, continue.
@markerikson
markerikson / redux-socket-middleware-example.js
Created June 28, 2018 00:37
Redux socket middleware example usage
const createMySocketMiddleware = (url) => {
return storeAPI => {
let socket = createMyWebsocket(url);
socket.on("message", (message) => {
storeAPI.dispatch({
type : "SOCKET_MESSAGE_RECEIVED",
payload : message
});
});
@claustres
claustres / rate_limiter_hook.js
Last active June 4, 2018 03:41
Rate limiting with FeathersJS - Concurrent
import { TooManyRequests } from 'feathers-errors'
import { RateLimiter } from 'limiter'
import makeDebug from 'debug'
const debug = makeDebug('debug')
export function rateLimit (options) {
const limiter = new RateLimiter(options.tokensPerInterval, options.interval)
return function (hook) {
if (hook.type !== 'before') {
@claustres
claustres / rate_limiter_config.js
Last active June 4, 2018 03:42
Rate limiting with FeathersJS - Config
module.exports = {
host: process.env.HOSTNAME || 'localhost',
port: 8081,
// Global API limiter
apiLimiter: {
http: {
windowMs: 60*1000, // 1 minutes window
delayAfter: 30, // begin slowing down responses after the 30th request
delayMs: 1000, // slow down subsequent responses by 1 seconds per request
max: 60 // start blocking after 60 requests
@claustres
claustres / rate_limiter.js
Last active June 4, 2018 03:41
Rate limiting with FeathersJS
import { RateLimiter as SocketLimiter } from 'limiter'
import HttpLimiter from 'express-rate-limit'
import { TooManyRequests } from 'feathers-errors'
import makeDebug from 'debug'
...
const debug = makeDebug('debug')
function setupSockets (app) {
const apiLimiter = app.get('apiLimiter')
const authConfig = app.get('authentication')