Skip to content

Instantly share code, notes, and snippets.

View alsamitech's full-sized avatar

Sami Alameddine alsamitech

  • Alsami Technologies
  • United States of America
View GitHub Profile
@alsamitech
alsamitech / CCC.c
Created October 17, 2020 03:30
Collatz Conjecture Calculator: Implementation in C
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Enter any number of type \"int\" : ");
int YinNum1;
scanf("%d yin",&YinNum1);
for(;;) {
if(YinNum1 % 2 == 0){
YinNum1=YinNum1/2;
@alsamitech
alsamitech / nokill.c
Created October 17, 2020 06:15
Makes a process that is not killable with ^C (Unix Only)
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
void handler(int num){
write(STDOUT_FILENO, "Kill Proceess Request Failed\n", 13);
}
@alsamitech
alsamitech / javagui.java
Created October 22, 2020 17:32
Java GUI With buttons
import javax.swing.*;
class Main{
public static void main(String args[]){
JFrame frame = new JFrame("My First GUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
JButton button1 = new JButton("Button 1");
JButton button2 = new JButton("Button 2");
frame.getContentPane().add(button1);
frame.getContentPane().add(button2);
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <X11/Xlib.h>
// CFLAGS=-lX11 -Os
/*
* Alsami utils, twin
**/
@alsamitech
alsamitech / atokl.c
Last active March 4, 2021 05:59
Compound Tokenizer
char** atokl(char* InC, char* delim, long unsigned int* len){
char** tok=(char**)malloc(2*sizeof(char*));
//printf("%p\n", tok);
tok[0]=strtok(strdup(InC), delim);
{
int i=1;
while(tok[i-1]!=NULL){
tok=(char**)realloc(tok, (i+1)*sizeof(char*));
tok[i]=strtok(NULL, delim);
// returns a heap duplicate up to n bytes
char* strndupx(char* in, long unsigned int n){
char* new=malloc(n+1);
new[n]=0x0;
memcpy(new, in, n);
return new;
}
@alsamitech
alsamitech / str_to_intarr.c
Created March 21, 2021 02:08
Converts a string into a heap-allocated array of integers
long unsigned int byte_instances(char* bytes, long unsigned int len, char byte){
long unsigned int inst=0;
for(long unsigned int i=0;i<len;i++){
if(bytes[i]==byte){
inst++;
}
}
return inst;
}
@alsamitech
alsamitech / read_file.c
Last active May 20, 2021 15:52
read_file - Reads a file from disk.
char* read_file(char* filenm, long unsigned int* len){
char* buf=0;
FILE* f=fopen(filenm, "rb");
if(f){
fseek(f,0,SEEK_END);
*len=ftell(f);
fseek(f,0,SEEK_SET);
buf=(char*)calloc(1, *len);
if(buf)
fread(buf, 1, *len, f);
@alsamitech
alsamitech / m_onetokl.c
Last active April 3, 2021 02:58
Just making my own strtok in C...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __unix__
#include <unistd.h>
#endif
#define s_foreach(x, y)\ for(long unsigned int y=0;x[y]!=0;y++)
@alsamitech
alsamitech / readfromfd1.c
Created April 5, 2021 06:53
Simply reads from file descripter one (stdin) for as long as it goes, similar to cin.getline in C++, just thought I'd add this.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __unix__
#include <unistd.h>
#else
#error Only supports unix!
#endif