Skip to content

Instantly share code, notes, and snippets.

View henryscala's full-sized avatar

henryscala henryscala

  • China
View GitHub Profile
@henryscala
henryscala / uDrawScreen.pas
Created February 7, 2022 10:03
pascal draw on screen
unit uDrawScreen;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,LCLIntf, LCLType;
type
@henryscala
henryscala / pyautogui-play.py
Created January 19, 2022 09:44
play the contents in a md file inside Typora
# used to play in the typora application
import pyperclip as pc
import pyautogui as pa
# specify input file before running
srcFileName=r"C:\tmp\pyautogui-play\grok-determinant.md"
# srcFileName=r"C:\tmp\pyautogui-play\test.md"
srcFile = open(srcFileName,mode='r', encoding='utf-8')
allFileLines = srcFile.readlines() # note, the '\n' is kept in each line
allFileLines = [ line.strip() for line in allFileLines]
@henryscala
henryscala / mariadb_operation_example.c
Created March 16, 2018 02:30
mariadb or mysql prepared statements example using C API
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <mysql/mysql.h>
/*
The program is a demonstration of using prepared statements to perform operations on the below table in mariadb.
The statements include: insert, select, delete, etc.
CREATE TABLE person (
@henryscala
henryscala / cpp_check_result_analysis.jl
Created January 5, 2018 08:29
a one-off script for cpp check result analysis
#!/usr/bin/env julia
function usage_exit()
println("$PROGRAM_FILE <cpp-check-result-file-name>")
exit()
end
#if length(ARGS) != 1
# usage_exit()
#end
@henryscala
henryscala / indent.py
Created December 8, 2016 10:05
a script to indent lines of text based on given start tag and end tag
# a script to indent lines of text based on given start tag and end tag
import os
import os.path
src_file = r"<sourcefile>"
dst_file = r"<destination-file>"
with open(src_file,"rb") as srcfile:
content = srcfile.read()
@henryscala
henryscala / dir_walk.py
Created December 8, 2016 09:32
a script to walk a dir, and filter each line of the files in that dir, and do something if the line fulfills some criteria
# a script to walk a dir, and filter each line of the files in that dir, and do something if the line fulfills some criteria
import os
import os.path
script_dir = r"<script-dir>"
dir_to_walk = r"<dir-to-walk>"
os.getcwd()
os.chdir(script_dir)
os.getcwd()
classes_file_name = os.path.join(script_dir, "<somefile.txt>" )
with open(classes_file_name) as file:
@henryscala
henryscala / yml2csv.py
Created May 25, 2016 06:50
Program to convert yaml to csv. only make sense for me.
input_lines = []
with open("account.yml",mode='r',encoding='utf-8') as f:
input_lines = f.readlines()
input_lines = [line.strip() for line in input_lines if line.strip() != '']
entries = []
entry = []
@henryscala
henryscala / sum_subset.go
Created March 11, 2016 08:38
using combination to get a subset of a set of numbers and then calculate whether the sum of the subset equals a specific target
package main
import (
"fmt"
"math/big"
"os"
)
var target int = 23813
var totalNum int = 69
@henryscala
henryscala / force_coredump.c
Created February 23, 2016 02:24
to force a coredump
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
/* this program tries to generate a crash. A prove of concept program. */
/* as per my test, crash may be created in other diectory, but not in my $HOME directory, I don't know why yet */
void function1() {
@henryscala
henryscala / dumpbuffer.c
Created February 1, 2016 02:16
a c function to dump the buffer in hex
#include <stdio.h>
char hexstr[]="0123456789ABCDEF";
void hexdump(char* buf, int len) {
int i;
for(i=0;i<len;++i) {
int hi=(buf[i] >> 4) & 0x0f;
int lo=(buf[i] & 0x0f);
printf("%c%c,",hexstr[hi],hexstr[lo]);
}