Skip to content

Instantly share code, notes, and snippets.

@root42
root42 / last_index_of.hh
Last active August 25, 2023 14:26
C++ string last_index_of similar to Java lastIndexOf
template<typename T>
typename T::size_type
last_index_of(const T &s, const T &q)
{
typename T::size_type
pos = std::string::npos,
res = std::string::npos;
while( (pos = s.find(q, (pos == std::string::npos ? 0 : pos + q.size()))) != T::npos) {
res = pos;
}
@root42
root42 / ws2812_plasma.py
Last active June 17, 2023 15:14
rpi_ws218x example program: plasma effect
#!/usr/bin/env python
import time
import math
import colorsys
from neopixel import *
# LED strip configuration:
LED_COUNT = 128 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
@root42
root42 / glob_exec.py
Last active May 17, 2023 09:53
Python exec with file globbing
#!/usr/bin/env python
#
# Executes the given command line by applying file globbing to all
# arguments but the first one. Example:
#
# ./glob_exec.py ls '*.py'
#
# This is useful for shells like Windows cmd which doesn't have native
# file globbing.
#

Coredump contains stack information as well. If you can use this stack information along with the EBP and EIP register values in the coredump file, you can print the stack trace. I had written a program to do this. You can find the program in the following link.

https://gist.github.com/root42/c979b037f85dc4b2be1f3735afedeb1d

Usage: Compile the above program and give the corefile when you execute it.

   $corestrace core

If you want symbols also to be printed, you do like this: Let's assume the program that generated the core is 'test'.

@root42
root42 / KOCH.BAS
Last active November 19, 2022 17:15
Let's Code MS DOS 0x1E: Power BASIC Snowflake
DIM angle AS SHARED DOUBLE
DIM COL AS SHARED INTEGER
DIM SCALE AS SHARED DOUBLE
'-------------------------------------------------------------------
' Make a turn in the curve, given in degrees
'-------------------------------------------------------------------
SUB turn (degrees AS DOUBLE)
angle = angle + degrees*3.14159265/180
END SUB
@root42
root42 / silent-night-omega2.py
Last active September 10, 2022 23:41
Plays "silent night" on a piezo buzzer attached to pin 18 of the Onion Omega2
#!/usr/bin/env python
# Plays "silent night" on a piezo buzzer attached to pin 18 of the Onion Omega2
# Things required: python lite, pwm needs to be enabled via:
# omega2-ctrl gpiomux set pwm0 pwm
from time import sleep
exportStr="/sys/class/pwm/pwmchip0/export"
periodStr="/sys/class/pwm/pwmchip0/pwm%s/period"
dutyStr="/sys/class/pwm/pwmchip0/pwm%s/duty_cycle"
@root42
root42 / viospa.asm
Created November 11, 2021 11:07
Detect video card in MS DOS
;*********************************************************************;
;* V I O S P A *;
;*-------------------------------------------------------------------*;
;* Task : Creates a function for determining the type *;
;* of video card installed on a system. This *;
;* routine must be assembled into an OBJ file, *;
;* then linked to a Turbo Pascal program. *;
;*-------------------------------------------------------------------*;
;* Author : Michael Tischer *;
;* Developed on : 10/02/88 *;
@root42
root42 / firework.bas
Created December 30, 2020 21:33
Let's Code MS-DOS 0x19: Fireworks in PowerBasic
$CPU 80286
$LIB EGA ON
$ERROR ALL OFF
$OPTIMIZE SPEED
$COMPILE EXE
defint A-Z
REM =================
REM Global variables
@root42
root42 / mode13.c
Created April 5, 2020 20:40
Using Turbo C with Inline Assembly
#include <conio.h>
#include <stdio.h>
int main()
{
unsigned char i;
int j;
asm mov ah, 0x00;
asm mov al, 0x13;
asm int 0x10;
@root42
root42 / fire.c
Created September 26, 2018 20:09
#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <conio.h>
#include <dos.h>
#include <mem.h>
#define VIDEO_INT 0x10
#define SET_MODE 0x00
#define VGA_256_COLOR_MODE 0x13