- Dado
$X \sim \mathcal{P}(\lambda)$ probar$\mathbb{E}(X) = \lambda$ $$\mathbb{E}(X) = \sum_{i=0}^\infty i \frac {\lambda^i}{i!} e^{-\lambda}$$ - Como vale
$0$ en$i=0$ puedo decir$$\mathbb{E}(X) = \sum_{i=1}^\infty i \frac {\lambda^i}{i!} e^{-\lambda}$$ - Simplifico
$i$ con$i!$ $$\mathbb{E}(X) = \sum_{i=1}^\infty \frac {\lambda^i}{(i-1)!} e^{-\lambda}$$ - Cambio de índices
$$\mathbb{E}(X) = \sum_{i=0}^\infty \frac {\lambda^{i+i}}{i!} e^{-\lambda}$$ - Saco constantes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crc_table = [ | |
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, | |
0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, | |
0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, | |
0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, | |
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, | |
0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401, | |
0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b, | |
0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, | |
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, |
Lets say you want to limit access to arbitrary code execution from a regular python runtime. What do you need to limit? This is a list of examples on how that is a futile mission (unless you REALLY want to limit the power of python).
- 01_using_os.py: The simplest thing, just do
os.spawn
- 02_using_subprocess.py: The
os
module was deprecated a loooong time ago. Why don't we use a modern library? - 03_using_ctypes.py: It's obvious to any well meaning programmer that
os
andsubprocess
are hairy modules. But do you remember thatctypes
exists? - 04_using_mmap.py: Woah! We can create executable memory FROM INSIDE python? That sounds incredible cursed.
- 05_using_open.py: ... just
open
? How? What do you mean with "/proc/self/mem bypasses memory protections"?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main: main.c lib.o | |
lib.o: lib.asm | |
nasm $< -f elf64 -o $@ | |
clean: | |
rm -f lib.o main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "keyboard_input.h" | |
#include "screen.h" | |
static void unrecognized_scancode(uint8_t scancode); | |
#define TOGGLE_SHIFT_IDX 1 | |
static void toggle_shift(uint8_t); | |
#define MOVE_DOWN_IDX 2 | |
static void move_down(uint8_t); | |
#define MOVE_UP_IDX 3 | |
static void move_up(uint8_t); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <limits.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
#include <stdio.h> | |
typedef uint32_t trie_key_t; | |
typedef float trie_value_t; | |
#define BRANCHING_FACTOR_LOG2 (CHAR_BIT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function duplication_automata() { | |
const digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
const vertices = [{type: 'start'}, {type: 'stop'}] | |
const edges = [] | |
for (const digit of digits) | |
vertices.push({type: 'internal', digit}) | |
for (const v of vertices) { | |
const add_edge = (to, match, output) => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <limits.h> | |
struct segment { | |
unsigned len; | |
unsigned next_free_segment; | |
unsigned* data; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#--------------------- game.py | |
#--------------------- header.py | |
instrucciones = [ | |
"You are the memory allocator: your job is to place code segments in RAM", | |
"Place the segments before the user loses her patience", | |
"Use space or right click to rotate memory segments", | |
"The score will increase as you optimize the space by making rectangular areas", | |
"When a segment is not yet optimized you can still move it", | |
"You get higher scores if your areas are more 'square'", | |
"When a memory segment is no longer needed it will be released by the GC", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# If you want to query the server for the mime uncomment the following line | |
#mime="$(curl -s -I "$1" | sed '/^content-type/I{s/content-type: //I; s/;.*$//; p};d' | tr -d '\r\n')" | |
# If you want to guess the mime uncomment the following line (requires perl-file-mimeinfo) | |
mime=$(mimetype -b "$1") | |
app="$(xdg-mime query default "${mime:-text/html}")" | |
gtk-launch "$app" $@ |
NewerOlder