Skip to content

Instantly share code, notes, and snippets.

View jotaki's full-sized avatar

Kinsella, Joseph (Joey) jotaki

View GitHub Profile
@jotaki
jotaki / mempass.c
Created January 6, 2020 16:47
get password into memory
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <termios.h>
int main(void)
{
char buf[BUFSIZ];
@jotaki
jotaki / helloworldlike.c
Created April 3, 2019 19:26
Not the traditional Hello, World
#include <stdio.h>
int main(int argc, char *argv[])
{
int i;
for(i=0;i<argc;i++) {
printf("Argument %d: %s\n", i, argv[i]);
}
}
@jotaki
jotaki / collatz.txt
Last active August 13, 2016 16:48
Playing with Collatz
given that:
f(2n) = n/2
f(2n+1) = 3n+1
we can see that the pattern translates to a pattern of 4x+(0,1,2,3) such that:
(4x+0)/2 = 2n (potentially 4x+2 or 4x+0)
(4x+1) = 2n+1
(4x+2)/2 = 2n+1
(4x+3) = 2n+1
@jotaki
jotaki / 99-llvm.patch
Created August 28, 2014 10:55
Patch used to compile uclibc-0.9.33.2-r11; Place in /etc/portage/patches/sys-libs/uclibc/. Allows for the succesful *compilation* of llvm-3.3-r3 (May break runtime)
diff -pruN a/include/errno.h b/include/errno.h
--- include/errno.h 2012-05-15 07:20:09.000000000 +0000
+++ include/errno.h 2014-08-28 10:08:31.046932387 +0000
@@ -87,7 +87,7 @@ extern __thread int errno attribute_tls_
might need this definition sometimes even if this file was included
before. */
#if defined __USE_GNU || defined __need_error_t
-# ifndef __error_t_defined
+# if !defined __error_t_defined && !defined error_t
typedef int error_t;
@jotaki
jotaki / min.c
Created November 14, 2013 13:27
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define LIST_SIZE 1024 * 1024 * 25
/* min by compare */
inline int mbc(int a, int b) { return a > b? b: a; }
@jotaki
jotaki / newnode.c
Last active December 24, 2015 17:59
struct node_s * add_node(struct node_s ** tree, struct node_s * leaf)
{
if(*tree == NULL)
*tree = leaf;
else if((*tree)->key > leaf->key) {
leaf->right = *tree;
*tree = leaf;
}
else if((*tree)->key < leaf->key) {
leaf->left = *tree;
.file "mynewx.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "numbers.txt"
.LC1:
.string "%u\n"
.LC2:
.string "%d in %ld ms\n"
.section .text.startup,"ax",@progbits
.p2align 4,,15
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void swap(int *p, int i, int j)
{
int t = p[i];
p[i] = p[j];
p[j] = t;
}
@jotaki
jotaki / x.c
Last active December 24, 2015 13:19
simple hash:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <sys/stat.h>
#define PATH "numbers.txt"
#define CHUNK_SIZE 4096
@jotaki
jotaki / for.c
Last active December 18, 2015 23:49
#include <stdio.h>
#include <time.h>
#include <omp.h>
int main()
{
unsigned long long l = 0, a = 0;
clock_t start, stop;
start = clock();