Skip to content

Instantly share code, notes, and snippets.

View disconnect3d's full-sized avatar
🎯
deadlocking the reality

Disconnect3d disconnect3d

🎯
deadlocking the reality
View GitHub Profile
@disconnect3d
disconnect3d / extract.sh
Last active September 2, 2019 11:52
One extract to rule them all - simple bash function to extract any archive
function extract() {
if [ $# -ne 1 ]; then
echo "Usage: $FUNCNAME filename"
fi
filename=$1
if [ -f $filename ]; then
case $filename in
*.tar.xz) tar xvfJ $filename ;;
*.tar.gz) tar --gzip -xvf $filename ;;
@disconnect3d
disconnect3d / template_loop.cpp
Last active November 29, 2015 21:36
C++ template for loop
#include <iostream>
using namespace std;
template<int c>
struct X
{
template<typename F>
static auto forEach(F func)
{
func(c);
@disconnect3d
disconnect3d / template_use_loop_counter_as_tpl_arg.cpp
Last active December 12, 2019 13:54
C++ template for loop which use loop counter as template argument
#include <iostream>
#include <array>
template<size_t c>
struct ForLoop {
template<template <size_t> class Func>
static void iterate() {
Func<c>()();
ForLoop<c-1>::template iterate<Func>();
}
@disconnect3d
disconnect3d / function_decl_trap.cpp
Last active December 2, 2015 13:06
"Default initialization trap"
#include <iostream>
using namespace std;
template <typename T>
struct X {
T x;
};
template <typename T>
@disconnect3d
disconnect3d / py_thread_clock.py
Last active June 24, 2018 12:06
Simple clock thread written in Python
#!/usr/bin/env python
from __future__ import print_function
import sys
import threading
import time
import datetime
class Clock(threading.Thread):
@disconnect3d
disconnect3d / name_mangling.py
Created February 4, 2016 19:54
Python tricky name mangling
class A:
def __a(self):
print("__a")
def _A__a(self):
print("_A__a")
def c(self):
self.__a()
self._A__a()
@disconnect3d
disconnect3d / monkeypatch.py
Last active October 21, 2020 09:23
Python - An attempt to disable possibility to monkeypatch method (NOTE: This can't be done right; don't do this at home)
class Person:
def __init__(self, name):
self.name = name
def __str__(self):
return "Person: {}".format(self.name)
if __name__ == "__main__":
def __str__(self):
return "xoxoxo"
@disconnect3d
disconnect3d / csp.py
Last active September 1, 2016 12:46
Disabling inline Javascript using CSP (Content-Security-Policy) header
from flask import Flask, make_response
app = Flask(__name__)
send_csp = True
csp = 'script-src'
html = """
Hello
<script>alert('xs')</script>
@disconnect3d
disconnect3d / generate_csrf.py
Created September 2, 2016 09:50
Generates POST CSRF html
"""
Takes input on stdin and generates html doing POST CSRF
E.g. input:
a=b&c=d
"""
import sys
import urllib
from collections import OrderedDict