Skip to content

Instantly share code, notes, and snippets.

@LukasWoodtli
LukasWoodtli / course_table_of_content.py
Created February 26, 2024 06:45
Get the table of content for a Coursera course
import requests
from bs4 import BeautifulSoup
if __name__ == '__main__':
req = requests.get("https://www.coursera.org/learn/dsp4?specialization=digital-signal-processing")
bs = BeautifulSoup(req.text)
tags = bs.find_all(lambda tag: tag.name == 'h3' or (tag.has_attr('data-test-id') and tag['data-test-id'] == 'item-view'))
for t in tags:
try:
#!/usr/bin/env python3
# -*- coding: ISO8859-15 -*-
# This might need some adjustments:
# Save file with the correct encoding and
# make sure that the chars to be replaced
# are encoded correctly in this file.
import os
import sys
// run it like this:
// stap -v -x <PID> system_tap_example.stp
global count;
probe begin {
count = 0;
printf("Staring system tap session for pid=%i\n", target());
}
#!/usr/bin/python
import subprocess
import re
import gdb
# This is just an example and might not work poperly!
class BreakpointAtMain(gdb.Breakpoint):
def __init__(self):
# This is just a small example. There are better tools to use when dealing with ELF files.
from hachoir.core.endian import LITTLE_ENDIAN
from hachoir.field import Parser, Bytes, UInt8, Enum, PaddingBytes, FieldSet, UInt16, UInt32
from hachoir.stream import FileInputStream
class Ident(FieldSet):
endian = LITTLE_ENDIAN
EI_NIDENT = 16
from bs4 import BeautifulSoup
with open(r'MyBool Packt.htm') as in_file:
soup = BeautifulSoup(in_file, 'html.parser')
toc = soup.find_all('ol', id="accordion-toc")
entry = soup.find_all('a', class_='toc-index')
for e in entry:
print(e.text.strip())
@LukasWoodtli
LukasWoodtli / markdown_code_snippet_converter.py
Last active April 4, 2022 13:15
Convert code snippets in Markdown to use fences
import fileinput
import os
import sys
# WARNING: This is Work-In-Progress!!!
def convert(inp):
code_snippet = False
for line in inp:
if code_snippet and line == "\n":
#!/usr/bin/env python3
"""Create labels with week numbers and dates"""
import os.path
from datetime import timedelta, date
import locale
locale.setlocale(locale.LC_ALL, 'DE_CH')
#include <sstream>
// poor man's unit testing framework
#define ASSERT_EQUALS(a, b) do { \
std::cerr << std::boolalpha; \
std::stringstream as, bs; \
as << a; bs << b; \
if (as.str() != bs.str()) { \
std::cerr << as.str() << "\nis not equal to\n" << bs.str() << "\nin line " << __LINE__ << std::endl; \
option(ENABLE_CPPCHECK "Enable cppcheck" OFF)
if(ENABLE_CPPCHECK)
find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck)
list(APPEND CMAKE_CXX_CPPCHECK
"--language=c++"
"--enable=warning,missingInclude"
"--inconclusive"
"--force"
"--inline-suppr")