This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// terminal raw mode is enabled: the keypress is registerred immediately after pressing | |
#include <errno.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/ioctl.h> | |
#include <termios.h> | |
#include <unistd.h> | |
void enableRAWMode(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple snippets to enable raw mode | |
// stdin is read as long as any key are pressed | |
// A simple testing function is included | |
// Note in raw mode "\n" is not interpreted with "\r" carriage return | |
// All "\n" shall be replaced with "\r\n" for normal effect | |
#include <errno.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <termios.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC=gcc | |
CWARNINGS=-Wall -Wextra -Wpedantic -Wformat=2 -Wswitch-default -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op -Wfloat-equal -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Waggregate-return -Wformat=2 -Wfatal-errors | |
COPTIMISING=-O0 -ggdb3 -fno-omit-frame-pointer -ffloat-store -fno-common -fstrict-aliasing -g | |
CFLAGS=-std=c11 $(CWARNINGS) $(COPTIMISING) -lm | |
INSTALL_DIR=$(HOME)/psu/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC=clang | |
CWARNINGS=-Wall -Wextra -Wpedantic -Wshadow -Wpointer-arith -Wcast-align \ | |
COPTIMISING=-O0 -ggdb3 -fno-omit-frame-pointer -fno-common -fstrict-aliasing | |
CFLAGS=-std=c11 $(CWARNINGS) $(COPTIMISING) | |
INSTALL_DIR=$(HOME)/psu/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# i3status configuration file. | |
# see "man i3status" for documentation. | |
# It is important that this file is edited as UTF-8. | |
# The following line should contain a sharp s: | |
# ß | |
# If the above line is not correctly displayed, fix your editor first! | |
general { | |
colors = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/types.h> | |
ssize_t getline(char **restrict lineptr, size_t *restrict n, | |
FILE *restrict stream) { | |
register char c; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// to run: go mod init <modname>; go tidy; go run . | |
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"github.com/davecgh/go-spew/spew" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"encoding/csv" | |
"log" | |
"os" | |
) | |
func readCsvFile(filePath string) [][]string { | |
f, err := os.Open(filePath) | |
if err != nil { | |
log.Fatal("Unable to read input file "+filePath, err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Expected input: a sorted array | |
// Return: index n, such that array[n] <= target < array[n+1] | |
func binarySearch(array []uint64, target uint64) (int, error) { | |
var lower, upper = 0, len(array) - 1 | |
var preLower, preUpper = 0, len(array) - 1 | |
for array[lower] > target || array[lower+1] <= target { | |
if array[lower+1] == target { | |
return lower + 1, nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package execBash | |
import ( | |
"bytes" | |
"os/exec" | |
) | |
func Execute(command string) (string, string, error) { | |
const ShellToUse = "bash" | |
var stdout bytes.Buffer |
OlderNewer