Skip to content

Instantly share code, notes, and snippets.

@merpnderp
merpnderp / fizzbuzz.js
Created December 11, 2020 20:47
Lol, old file I found, the evolution of my FizzBuzz attempts.
Array.from({ length: 100 }, (v, i) => [[15, 'fizzbuzz'], [5, 'buzz'], [3, 'fizz']]).find(x => (i+1) % x[0] === 0) || (i + 1)).reduce((a, o) => a += (o[1] || o) + "\n",'')
return
for(var i = 1; i< 101; i++){
console.log( (i%3 === 0 ? 'FIZZ' + (i%5 === 0 ? 'BUZZ' : '') : i%5 === 0 ? 'BUZZ' : i))
}
return
/*
for(var i=1; i<101; i++){
@merpnderp
merpnderp / gist:59a26dcea8ed498f9bab99881af29d69
Created June 30, 2017 14:50
Raspberry pi setup wifi without keyboard/mouse
There's an easier way for the SSH and wifi:
* flash the card with etcher
* put empty file called "ssh" on SD card
* put "wpa_supplicant.conf" file on SD card
* insert SD card in Pi Zero W
You're done, Pi will boot with SSH enabled and will automatically connect to wifi.
@merpnderp
merpnderp / cache.js
Created June 28, 2017 20:15
lru-cache wrapper
const LRU = require("lru-cache")
const options = {
max: 500,
// length: function (n, key) { return n * 2 + key.length },
// dispose: function (key, n) { n.close() },
maxAge: 1000 * 60 * 60
}
const cache = LRU(options)
export default cache
@merpnderp
merpnderp / package.json
Created May 9, 2017 14:46
webpack example
{
"name": "reactcomponents",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack --debug --watch --colors",
"build": "webpack -p --optimize-minimize --config webpack.production.config.js",
"watch": "webpack --debug --watch",
@merpnderp
merpnderp / rxExample.js
Created March 21, 2017 03:05
RX.js example
<html>
<input id="input"></input>
<div id='results'></div>
<script src="https://code.jquery.com/jquery.js"></script>
<script src="https://cdn.jsdelivr.net/rxjs/4.1.0/rx.lite.min.js"></script>
<script>
const $input = $('#input');
const $results = $('#results');
@merpnderp
merpnderp / .vimrc
Last active March 23, 2017 20:00
.vimrc
filetype plugin indent on
syntax on
set shiftwidth=2
set tabstop=2
set hlsearch
set ignorecase " Do case insensitive matching
set incsearch " Incremental searcha
set showmatch " Show matching brackets
set smartcase " Do smart case matching
set virtualedit=block " Square up visual selections
@merpnderp
merpnderp / sempahore.js
Last active February 15, 2017 15:11
My Node Semaphore code written in response to irc #node programming challenge
//-------------------------------------------------------
// QUESTION: Can you implement the Semaphore type?
//
// In systems programming, it is sometimes important
// to restrict the requests made to a given resource.
// The resource may be a CPU bound process, or a
// network resource. Controlling throughput to that
// resource can be challenging, but simplified through
// the use of a semaphore like primitive.
//
@merpnderp
merpnderp / index.js
Last active February 23, 2017 04:44
Pull Blood Pressure readings from IOS Health
var fs = require("fs");
if (!process.argv[2]) {
console.log("Must pass in target file!!");
process.exit(1);
}
fs.readFile(__dirname + "/" + process.argv[2], "utf8", function(err, data) {
data = data.split(/\n/);
var sys = [], dia = [];
I don't like to use any third party tools. Hence I used a combination of ssh configuration and firewall settings. With the following solution an attacker is allowed to produce exactly 3 fault logins in 2 minutes, until he will be blocked for 120 seconds.
1) Add the following line to /etc/ssh/sshd_config
MaxAuthTries 1 #This locked me out of my server
2) Add the following firewall rules
@merpnderp
merpnderp / test.js
Created July 1, 2015 16:37
Promise example
var fs = require('fs');
function nodeToPromise(resolve, reject){
return function(err, value){
if(err){reject(err);} else{resolve(value)}
};
}
function readFileAsync(file = "./t.js"){
return new Promise((resolve, reject) =>{