Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
def main():
'''
This is the Python equivalent to the following C code:
int n;
printf("Enter a Number");
scanf("&d",n);
if(n==1)
printf("true");
<!DOCTYPE html>
<html>
<body>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<style>
h1,h2,h3,h4,h5,h6,p,label,input {font-family: 'Lato', sans-serif;}
body {padding: 2rem;}
</style>
@classmember
classmember / file_perms_eq.sh
Created May 9, 2018 15:32
file_perms_eq.sh
# function: file_perms_eq
# description: checks first option (filename) to see if the file perms equals the second option (permissions)
# usage example:
# $ if file_perms_eq mail 700
# > then echo 'good'
# > fi
file_perms_eq() { (( $(stat -c "%a" $1) == $2 ));}
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}() [${PIPESTATUS[*]}] }'
const { map, filter, reduce } = require('lodash');
// array from 0 to 9
const data = [0,1,2,3,4,5,6,7,8,9];
// helper functions
const doubled = val => val * 2;
const isEven = val => val % 2;
const isOverTen = val => val >= 10;
#!/bin/sh
FORMAT="{
\"name\": \"%n\",
\"access\": \"%A\",
\"size\": \"%s\"
},
"
printf "$(stat --printf="${FORMAT}" $*)"
printf "\b"
'''
dive
open a gdb session targeting a python compiled with gdb debugging enabled
alias dive='gdb -iex '\''add-auto-load-safe-path .'\'' /opt/cpython/python'
in gdb:
b 1
r
s
upstream php {
server unix:/var/run/php/php7.2-fpm.sock;
server 127.0.0.1:9000;
}
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;

Watching all layers of Python code

We're going to dive into how languages interact as a stack. First, we'll download the a copy of Python and compile with GNU debugging tags enabled. I hope you're ready to watch registers in the processor flutter and C code scroll. We start by opening our favorite terminal.

Compile a debugging build of Python

Go to the directory the debugging build will be installed in

cd /opt/
@classmember
classmember / brython example
Created July 1, 2019 13:18
Python in the browser
<html>
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.7.3/brython.min.js"> </script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.7.3/brython_stdlib.js"></script>
</head>
<body onload="brython()">
<script type="text/python">
from browser import document, alert
def echo(event):