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 / 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 / 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 / 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 / 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
@disconnect3d
disconnect3d / list_docker_containers.py
Last active September 29, 2016 09:08
Simple server listing docker containers with exposed ports as links on all network interfaces. Works with Python 3; `pip install flask` is required.
#!/usr/bin/env python3
# flask is required - install with `pip install flask`
import sys
import subprocess
from flask import Flask
if len(sys.argv) < 2:
print("Usage: %s <public ip>" % sys.argv[0])
@disconnect3d
disconnect3d / binary_addition.py
Last active November 15, 2016 20:18
"First steps programming exercise to add two binary numbers" lol
def add(b1, b2):
result = []
carry = 0
for i, j in zip(reversed(b1), reversed(b2)):
tmp = int(i) + int(j) + carry # 0, 1, 2
#print("i=%s, j=%s, carry=%d" % (i, j, carry))
carry = tmp / 2
tmp = tmp % 2
/*
//// Decompiled from .so compiled with Cython
//// hidden.pyx code:
import numpy as np
def bar(x):
print "Hello from bar"
arr = np.array(x)
return arr * arr.T