Skip to content

Instantly share code, notes, and snippets.

@stenno
stenno / proxy.js
Last active September 16, 2020 16:21
matrix behavior on array with Proxy
const [width, height] = [10,10] // 10x10 matrix
const element = (index) => index;
// lets create the flat array first
const array = Array.from({length: width * height}, (_,index) => element(index));
// lets create the proxy handler
// we return the 'row' of the index by filtering the respective elements
@stenno
stenno / EnabledRoute.js
Last active February 4, 2020 13:07
Enabling routes with Role-based auth
import React, { useContext} from 'react';
import { useRouteMatch } from 'react-router-dom';
import UserContext from '../context/UserContext';
import routes from './routes';
const EnabledRoute = (props) => {
const { roles } = useContext(UserContext);
const { name, exact, component: Component } = props;
const { role, route: path } = routes.find(route => route.name === name);
@stenno
stenno / SecurityController.php
Last active October 27, 2021 06:05
Getting role hierarchy of logged in user in Symfony 5
<?php
namespace App\Controller;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
class SecurityController extends AbstractController
{
Jul 10 16:21:42 texfbggzw01 kernel: IN=eth0 OUT=eth0 SRC=195.124.8.1 DST=10.106.122.211 LEN=52 TOS=0x00 PREC=0x00 TTL=124 ID=6467 DF PROTO=TCP SPT=62397 DPT=3389 WINDOW=64896 RES=0x00 SYN URGP=0
Jul 10 16:21:45 texfbggzw01 kernel: IN=eth0 OUT=eth0 SRC=195.124.8.1 DST=10.106.122.211 LEN=52 TOS=0x00 PREC=0x00 TTL=124 ID=6478 DF PROTO=TCP SPT=62397 DPT=3389 WINDOW=64896 RES=0x00 SYN URGP=0
Jul 10 16:21:51 texfbggzw01 kernel: IN=eth0 OUT=eth0 SRC=195.124.8.1 DST=10.106.122.211 LEN=52 TOS=0x00 PREC=0x00 TTL=124 ID=6486 DF PROTO=TCP SPT=62397 DPT=3389 WINDOW=64896 RES=0x00 SYN URGP=0
# Generated by iptables-save v1.4.7 on Wed Jul 10 16:13:49 2019
*nat
:PREROUTING ACCEPT [360:24859]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A PREROUTING -d 10.106.3.96/32 -p tcp -m tcp --dport 60000 -j DNAT --to-destination 10.106.122.211:3389
-A POSTROUTING -d 10.106.122.221/32 -p tcp -m tcp --dport 3389 -j SNAT --to-source 10.106.3.96
-A POSTROUTING -o eth0 -j MASQUERADE
-A POSTROUTING -j LOG
-A OUTPUT -d 10.106.3.96/32 -p tcp -m tcp --dport 60000 -j DNAT --to-destination 10.106.122.221
@stenno
stenno / golf.js
Created July 7, 2019 16:59
vowelratio golf
n=>(g=(a,b)=>b?g(b,a%b):a,[c=(n.match(/[b-df-hj-np-tv-z]/gi)||[]).length,v=(n.match(/[aeiou]/gi)||[]).length],`${c==0?1:v/g(v,c)}:${v==0?1:c/g(v,c)}`)
@stenno
stenno / seq.js
Last active June 6, 2019 14:31
for-of vs. reduce for sequential promises
const urls = ['foo', 'bar','baz'];
// for-of
for (const url of urls) {
const result = await fetch(url);
console.log(result);
}
// reduce
urls.reduce((chain, url) => chain.then(fetch(url)), Promise.resolve()).forEach(result => console.log(result));
@stenno
stenno / handmage.txt
Created May 21, 2019 20:11
Khadgar handmage
### khadgar handmage
# Class: Mage
# Format: Standard
# Year of the Dragon
#
# 2x (2) Acidic Swamp Ooze
# 2x (2) Book of Specters
# 2x (2) Firetree Witchdoctor
# 1x (2) Khadgar
# 2x (2) Sunfury Protector
@stenno
stenno / sshtrap.sh
Created May 1, 2019 09:45
ssh trap?
trap "echo 'hello'; exit" 1
ssh nethack@eu.hardfought.org
#other shell
kill -1 12345
# 'hello' is not printed
@stenno
stenno / minDate.js
Created April 29, 2019 10:29
angular isBeforeMinDate
scope.isBeforeMinDate = (month, first) => {
const { year } = scope.currentSelection;
const date = moment(`${first ? '01' : '15'}-${month}-${year}`, 'DD.MM.YYYY');
$log.info("GOING TO RETURN ", !!(scope.earliestMoment && date.isBefore(scope.earliestMoment)));
return (scope.earliestMoment && date.isBefore(scope.earliestMoment)) ? true : false;
}