Skip to content

Instantly share code, notes, and snippets.

View kleinron's full-sized avatar
🦉
C'est moi

Ron Klein kleinron

🦉
C'est moi
View GitHub Profile
class DynamicArrayQueue {
constructor() {
this._arr = [];
}
enqueue(item) {
this._arr.push(item);
}
dequeue() {
@kleinron
kleinron / extended.ts
Created November 13, 2021 21:13
queue interface
interface Queue extends Iterable<any>{
enqueue(item: any): void;
dequeue(): any;
clear(): void;
size(): number;
peekFirst(): any;
peekLast(): any;
copyTo(arr: any[], startIndex?: number): void
drainingIterator(): Iterator<any>;
toJSON(): any[];
@kleinron
kleinron / core.ts
Created November 13, 2021 21:12
queue interface
interface Queue {
enqueue(item: any): void;
dequeue(): any;
}
@kleinron
kleinron / morgan-x-forwarded-for.js
Created May 18, 2015 21:31
When using Morgan as the access log writer, in a Vanilla server, use this snippet to respect the x-forwarded-for header as the original client's ip address.
morgan.token('remote-addr', function (req, res) {
var ffHeaderValue = req.headers['x-forwarded-for'];
return ffHeaderValue || req.connection.remoteAddress;
});
@kleinron
kleinron / lzma_sample.cpp
Created June 25, 2020 13:43 — forked from Treeki/lzma_sample.cpp
simple LZMA SDK compression/decompression example
// note: -D_7ZIP_ST is required when compiling on non-Windows platforms
// g++ -o lzma_sample -std=c++14 -D_7ZIP_ST lzma_sample.cpp LzmaDec.c LzmaEnc.c LzFind.c
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <memory>
#include "LzmaEnc.h"
#include "LzmaDec.h"
import sys
from itertools import zip_longest
from traceback import print_exc
def grouper(iterable, n, fillvalue=None):
"""Collect data into fixed-length chunks or blocks"""
# grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return zip_longest(*args, fillvalue=fillvalue)
@kleinron
kleinron / express_item.js
Created February 18, 2020 10:35
demonstrate code improvements
import * as request from "superagent";
export class TokenExtractMiddleware {
constructor() {
}
extract = (req, res, next) => {
const url = `${process.env.AUTH_SERVICE}/auth/authenticate`;
class hn_wrapper(object):
def __init__(self, it):
self.it = iter(it)
self._hasnext = None
def __iter__(self): return self
def next(self):
if self._hasnext:
result = self._thenext
else:
result = next(self.it)
@kleinron
kleinron / enableGzip.java
Last active January 24, 2019 18:50
spark java enable gzip if needed
private static void enableGzipIfNeeded(spark.Request request, spark.Response response) {
String accept = request.headers("Accept-Encoding");
if (accept == null) {
return;
}
String[] tokens = accept.split(",");
if (Arrays.stream(tokens).map(String::trim).anyMatch(s -> s.equalsIgnoreCase("gzip"))) {
response.header("Content-Encoding", "gzip");
}
}
@kleinron
kleinron / rsa-example.txt
Created December 11, 2018 19:32
rsa example
https://8gwifi.org/RSAFunctionality?keysize=512
-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKanYhwoySc0JjNjqT21f+4hXP+e1g1h
dz9wNj0XHii1luZtn8ydFRpzMF5CgECYO4jHMbuB2ZnPXU6Ar7t57HMCAwEAAQ==
-----END PUBLIC KEY-----
-----BEGIN RSA PRIVATE KEY-----
MIIBOQIBAAJBAKanYhwoySc0JjNjqT21f+4hXP+e1g1hdz9wNj0XHii1luZtn8yd
FRpzMF5CgECYO4jHMbuB2ZnPXU6Ar7t57HMCAwEAAQJACcZfls89nTMN2o3J63it