Last active
May 9, 2020 08:30
-
-
Save lukas-h/ce4b68be955a7e24621e12ff3d09677b to your computer and use it in GitHub Desktop.
Some old snippets
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
/* ~ write all ascii characters into a file~ | |
Is this program useful? NO!!! It's an obfuscated program that does nothing!!!*/ | |
#include <stdio.h> | |
main(){FILE*f=fopen("ASCIITABLE.txt","w");char i=0x0;while | |
(f!=NULL){putc(i,f);if(i==0x7E){break;}else{i++;}}fclose(f);} |
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 <termios.h> | |
#include <unistd.h> | |
#include <signal.h> | |
/* | |
Info: | |
This program outputs the actual char (received from keyboard) and shows it as char and decimal. | |
It is useful for escape sequences, like the function buttons on the keyboard (F1, F2, ..., F12) | |
or e.g arrow keys, etc... | |
Licensing: | |
Copyright 2016 Lukas Himsel <lukas.himsel@web.de> | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation; either version 2 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
MA 02110-1301, USA. | |
*/ | |
const char *table[33] = { | |
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", | |
"BS", "TAB", "LF", "VT", "FF", "CR", "SO", "ST", "DLE", | |
"DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", | |
"EM", "SUB", "ESC", "FS", "GS", "RS", "US", "SPACE" | |
}; | |
/* | |
first 32 (non-printable [invisible] characters from ASCII table) | |
Dec Char Description | |
0 NUL null | |
1 SOH start of heading | |
2 STX start of text | |
3 ETX end of text | |
4 EOT end of transmission | |
5 ENQ enquiry | |
6 ACK acknowledge | |
7 BEL bell | |
8 BS backspace | |
9 TAB horizontal tabulator | |
10 LF NL line feed (enter, new line) | |
11 VT vertical tab. | |
12 FF NP from feed, new page | |
13 CR carriage return | |
14 SO shift out | |
15 ST shift in | |
16 DLE data link escape | |
17 DC1 device control 1 | |
18 DC2 device control 2 | |
19 DC3 device control 3 | |
20 DC4 device control 4 | |
21 NAK negative acknowledge | |
22 SYN synchronous idle | |
23 ETB end of trans. block | |
24 CAN cancel | |
25 EM end of medium | |
26 SUB substitute | |
27 ESC escape | |
28 FS file separator | |
29 GS group separator | |
30 RS record separator | |
31 US unit separator | |
32 SPACE whitespace | |
*/ | |
static int getch(void); | |
int main(){ | |
int c=0; | |
while(1){ | |
c=getch(); | |
if(c < 33){ | |
printf("\033[31m%s\033[0m, %d\n", table[c], c); | |
} else{ | |
printf("\033[32m%c\033[0m, %d\n", c,c); | |
} | |
} | |
return 0; | |
} | |
/* getch function from github.com/lukas-h/getch.c */ | |
static struct termios _term; | |
static void on_signal (int signal){ | |
tcsetattr(STDIN_FILENO, TCSANOW, &_term); | |
exit(1); | |
} | |
int getch (void){ | |
int c = EOF; | |
struct termios term, ttmp; | |
tcgetattr(STDIN_FILENO, &term); | |
tcgetattr(STDIN_FILENO, &_term); | |
ttmp = term; | |
ttmp.c_lflag &= ~(ICANON|ECHO); | |
tcsetattr(STDIN_FILENO, TCSANOW, &ttmp); | |
signal(SIGABRT, on_signal); | |
signal(SIGINT, on_signal); | |
signal(SIGKILL, on_signal); | |
signal(SIGQUIT, on_signal); | |
signal(SIGSTOP, on_signal); | |
signal(SIGTERM, on_signal); | |
c = getchar(); | |
tcsetattr(STDIN_FILENO, TCSANOW, &term); | |
return 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
#include <math.h> | |
double nroot(double x, double n){ return pow(x, (1/n)); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment