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 / 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.
#
@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 / 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 / thread.cc
Created November 14, 2019 12:05
How to crash a thread with a shared_ptr reference
#include <memory>
#include <iostream>
#include <thread>
int main()
{
std::shared_ptr<std::thread> mythread;
mythread.reset(
@root42
root42 / assignment.cc
Created November 14, 2019 09:19
Destructors when using shared_ptr assignments
#include <iostream>
#include <memory>
class Base
{
public:
Base() { std::cout << "Base constructor" << std::endl; }
virtual ~Base() { std::cout << "Base destructor" << std::endl; }
};
@root42
root42 / # guile - 2019-01-15_05-52-06.txt
Created January 15, 2019 15:46
guile on "CentOS release 6.9 (Final)" - Homebrew build logs
Homebrew build logs for guile on "CentOS release 6.9 (Final)"
Build date: 2019-01-15 05:52:06
@root42
root42 / # shellcheck - 2018-12-20_14-24-55.txt
Created December 20, 2018 13:27
shellcheck on Ubuntu 18.04.1 LTS - Homebrew build logs
Homebrew build logs for shellcheck on Ubuntu 18.04.1 LTS
Build date: 2018-12-20 14:24:55