Skip to content

Instantly share code, notes, and snippets.

@bricef
bricef / monkey.py
Last active May 16, 2024 03:31
Monkey patching of builtins in Python3
# found this from Armin R. on Twitter, what a beautiful gem ;)
import ctypes
from types import MappingProxyType, MethodType
# figure out side of _Py_ssize_t
if hasattr(ctypes.pythonapi, 'Py_InitModule4_64'):
_Py_ssize_t = ctypes.c_int64
else:
_Py_ssize_t = ctypes.c_int
@bricef
bricef / PaddingOracle.py
Created September 8, 2016 20:56
Padding Oracle attack example in python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
import sys
from Crypto.Cipher import AES
BLOCK_SIZE = 16 # bytes
INIT_VEC = 'This is an IV456' # hardcoding this is a terrible idea
@bricef
bricef / Hash.cs
Last active October 3, 2016 00:41
Salting and Hashing passwords correctly in .NET
/**
* From http://lockmedown.com/hash-right-implementing-pbkdf2-net/
*/
public class Hash
{
private const int SaltByteLength = 32;
private const int DerivedKeyLength = 32;
private const int IterationCount = 48000;
private const char separator = '|';
<html>
<body>bucket served file ok</body>
</html>
@bricef
bricef / party.dot
Last active February 13, 2018 15:30
Abduction: Bat out of hell party - attitude graph
//➤ neato party.dot -Gsep="+200" -Goverlap=scalexy -Tpng -o party.png && open party.png
digraph party {
Ad [label="Adric"];
Az [label="Azrael"];
P [label="Peridot"];
Li [label="Liberace"];
Pe [label="Pete"];
K [label="Koros"];
Lu [label="Luth"];
F [label="Fletcher"];
@bricef
bricef / docker-compose output
Last active February 19, 2018 18:00
Error on following readme instructions
➤ docker-compose -f services/dev.yml up --build
Starting services_api_1 ... done
Starting services_web_1 ... done
Attaching to services_api_1, services_web_1
api_1 |
api_1 | > json-server@ prestart /home
api_1 | > npm install
api_1 |
web_1 |
web_1 | > [email protected] prestart /home
1 - ???
2 - The Matrix
3 - Speed
4 - Leaving Las Vegas
5 - Lalaland
6 - 12 monkeys
7 - π
8 - Dr No
9 - Seven
10 - Home Alone
B_BLACK="\[\e[40m\]"
B_RED="\[\e[41m\]"
B_GREEN="\[\e[42m\]"
B_YELLOW="\[\e[43m\]"
B_BLUE="\[\e[44m\]"
B_MAGENTA="\[\e[45m\]"
B_CYAN="\[\e[46m\]"
B_WHITE="\[\e[47m\]"
F_BLACK="\[\e[30m\]"
@bricef
bricef / merge_mappings.py
Last active December 13, 2019 20:27 — forked from angstwad/dict_merge.py
Recursive dictionary merge in Python
# Recursive dictionary merge
# Copyright (C) 2019 Brice Fernandes <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@bricef
bricef / tmp_file_value_context.py
Created January 18, 2020 07:16
Given a value, create a temporary file and make this file available for the duration of the context.
class ValueContext(object):
"""
A ValueContext is constructed from a value that can be writtent to a file
and then exposes the value as a temporary file in its context.
The temporary file path can be accessed using its `name` attribute.
For example: