diff options
author | EliteTK <tomasz.kramkowski@gmail.com> | 2014-04-24 09:06:24 +0100 |
---|---|---|
committer | EliteTK <tomasz.kramkowski@gmail.com> | 2014-04-24 09:06:24 +0100 |
commit | a98d134e89a42909721dcefd426118af38628048 (patch) | |
tree | cdf43f11ed4aafbc46fe813584851612ae7c3c89 | |
parent | c1a966057407d815d054ddbd2432badda91d4379 (diff) | |
download | c-stuff-a98d134e89a42909721dcefd426118af38628048.tar.gz c-stuff-a98d134e89a42909721dcefd426118af38628048.tar.xz c-stuff-a98d134e89a42909721dcefd426118af38628048.zip |
Latest random crap.
-rw-r--r-- | box.c | 10 | ||||
-rw-r--r-- | cursor_remove.c | 6 | ||||
-rw-r--r-- | encrypt.c | 10 | ||||
-rw-r--r-- | foursquare.c | 121 | ||||
-rw-r--r-- | genkeypairs.c | 32 | ||||
-rw-r--r-- | gtk.c | 79 | ||||
-rw-r--r-- | revlist.c | 31 | ||||
-rw-r--r-- | vixus.c | 41 | ||||
-rw-r--r-- | xlibtest.c | 59 |
9 files changed, 389 insertions, 0 deletions
@@ -0,0 +1,10 @@ +#include <stdio.h> + +int main(int argc, char **argv) +{ + if(argc != 2){ + printf("\33[?25l"); + } else { + printf("\33[?25h"); + } +} diff --git a/cursor_remove.c b/cursor_remove.c new file mode 100644 index 0000000..a413709 --- /dev/null +++ b/cursor_remove.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main(int argc, char **argv) +{ + printf("\33[8m"); +} diff --git a/encrypt.c b/encrypt.c new file mode 100644 index 0000000..6a8ca12 --- /dev/null +++ b/encrypt.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char **argv) +{ + srand(time(NULL)); + char c; + while((c = getchar()) != EOF) + putchar((char)((double)rand() / (double)RAND_MAX * (double)256)); +} diff --git a/foursquare.c b/foursquare.c new file mode 100644 index 0000000..9552ed4 --- /dev/null +++ b/foursquare.c @@ -0,0 +1,121 @@ +// foursquare.c +#include <stdio.h> +#include <ctype.h> +#include <stdlib.h> +#include <string.h> + +#define Q ('Q'-'A') + +typedef struct vec2 { + int x; + int y; +} Vec2; + +int increinc(int *); +void allupper(char *); +void genkey(char *, char *); +Vec2 *newVec2(const int, const int); + +int main(int argc, char **argv) +{ + int x, y, c=0; + + if(argc!=4){ + printf("Usage: %s <key1> <key2> <cipher>", *argv); + exit(1); + } + + printf("%s, %s ", *(argv+1), *(argv+2)); + + char *trkey = *(argv+1); + allupper(trkey); + char *trfullkey = malloc(26); + genkey(trkey, trfullkey); + + char *blkey = *(argv+2); + allupper(blkey); + char *blfullkey = malloc(26); + genkey(blkey, blfullkey); + + char *cipher = *(argv+3); + allupper(cipher); + + int i=0; + Vec2 *trtable[25]; + for(x=0; x<5; x++) + for(y=0; y<5; y++) + trtable[trfullkey[i++]-'A'] = newVec2(x, y); + free(trfullkey); + + i = 0; + Vec2 *bltable[25]; + for(x=0; x<5; x++) + for(y=0; y<5; y++) + bltable[blfullkey[i++]-'A'] = newVec2(x, y); + free(blfullkey); + + char basetable[5][5]; + for(x=0; x<5; x++) + for(y=0; y<5; y++){ + if(c==Q) + c++; + basetable[x][y] = 'A' + c++; + } + + for(i=0; i<strlen(cipher)/2; i++){ + char c1 = cipher[2*i]; + char c2 = cipher[2*i+1]; + + putchar(basetable[trtable[c1-'A']->x][bltable[c2-'A']->y]); + putchar(basetable[bltable[c2-'A']->x][trtable[c1-'A']->y]); + } + putchar('\n'); + + for(i=0; i++; i<25){ + free(trtable[i]); + free(bltable[i]); + } + + return 0; +} + +int increinc(int *num) +{ + (*num)++; + return (*num)++; +} + +void allupper(char *input) +{ + int i; + for(i=0; i<strlen(input); i++) + if(isalpha(input[i])) + input[i]=toupper(input[i]); +} + +void genkey(char *input, char *output) +{ + int dict[26]; + memset(dict, 0, 26*sizeof(int)); + + int i, outpt = 0; + for(i=0; i<strlen(input); i++){ + if(!dict[input[i]-'A']){ + output[outpt++]=input[i]; + } + dict[input[i]-'A'] += 1; + } + + for(i=0; i<26; i++) + if(!dict[i] && i!=Q) + output[outpt++]=i+'A'; + output[outpt]='\0'; +} + +Vec2 *newVec2(const int x, const int y) +{ + Vec2 *v = malloc(sizeof(Vec2)); + v->x = x; + v->y = y; + return v; +} diff --git a/genkeypairs.c b/genkeypairs.c new file mode 100644 index 0000000..df4bc3d --- /dev/null +++ b/genkeypairs.c @@ -0,0 +1,32 @@ +// genkeypairs.c +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define MAXLIST 1000 +#define MAXKEY 100 + +int main(int argc, char **argv) +{ + int c, i, ii, listsize; + char *list[MAXLIST]; + char *word = malloc(MAXKEY+1); + for(i=0; i<MAXLIST; i++) + if(!getword(word, MAXKEY)) + break; + else + memcpy(list[i]=malloc(strlen(word)+1), word, strlen(word)+1); + listsize = ++i; + for(i=0; i<listsize; i++) + for(ii=i+1; ii<listsize-1; ii++) + printf("./justkeys %s %s\n", list[i], list[ii]); +} + +int getword(char *output, int maxlength) +{ + int c, p=0; + while((c=getchar())!=EOF && isalpha(c) && p<maxlength) + output[p++] = (char)c; + output[p] = '\0'; + return p; +} @@ -0,0 +1,79 @@ +#include<gtk/gtk.h> + +gint count = 0; +char buf[5]; + +void increase(GtkWidget *widget, gpointer label) +{ + count++; + + sprintf(buf, "%d", count); + gtk_label_set_text(GTK_LABEL(label), buf); +} + +void decrease(GtkWidget *widget, gpointer label) +{ + count--; + + sprintf(buf, "%d", count); + gtk_label_set_text(GTK_LABEL(label), buf); +} + + +GdkPixbuf *create_pixbuf(const gchar *filename) +{ + GdkPixbuf *pixbuf; + GError *error = NULL; + pixbuf = gdk_pixbuf_new_from_file(filename, &error); + if(!pixbuf) { + fprintf(stderr, "%s\n", error->message); + g_error_free(error); + } + + return pixbuf; +} + +int main(int argc, char **argv) +{ + + GtkWidget *label; + GtkWidget *window; + GtkWidget *frame; + GtkWidget *plus; + GtkWidget *minus; + + gtk_init(&argc, &argv); + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(window), "Yay!"); + gtk_window_set_default_size(GTK_WINDOW(window), 250, 180); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); + gtk_window_set_icon(GTK_WINDOW(window), create_pixbuf("/home/main/Media/Pictures/GTKTutIcon.png")); + + frame = gtk_fixed_new(); + gtk_container_add(GTK_CONTAINER(window), frame); + + plus = gtk_button_new_with_label("+"); + gtk_widget_set_size_request(plus, 50, 20); + gtk_fixed_put(GTK_FIXED(frame), plus, 50, 20); + + minus = gtk_button_new_with_label("-"); + gtk_widget_set_size_request(minus, 50, 20); + gtk_fixed_put(GTK_FIXED(frame), minus, 50, 80); + + label = gtk_label_new("0"); + gtk_fixed_put(GTK_FIXED(frame), label, 190, 58); + + gtk_widget_show_all(window); + + g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); + + g_signal_connect(plus, "clicked", G_CALLBACK(increase), label); + + g_signal_connect(minus, "clicked", G_CALLBACK(decrease), label); + + gtk_main(); + + return 0; +} + diff --git a/revlist.c b/revlist.c new file mode 100644 index 0000000..4c5dddb --- /dev/null +++ b/revlist.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +int main(int argc, char **argv) +{ + if(argc != 3){ + fprintf(stderr, "Incorrect argument count.\nUsage: %s <string> <separator>\n"\ + , argv[0]); + exit(1); + } + + char *input = argv[1]; + char separator = argv[2][0]; + int length = strlen(input), startpos = 0, strpos; + + char *output = malloc(length); + + for(strpos = 0; strpos <= length; strpos ++){ + if(input[strpos] == separator || strpos == length){ + strncpy(output + length - strpos, input + startpos, strpos - startpos); + if(strpos != length) + output[length - strpos - 1] = separator; + startpos = strpos + 1; + } + } + + printf("%s\n", output); + free(output); + return 0; +} @@ -0,0 +1,41 @@ +#include <X11/Xft/Xft.h> +#include <X11/Xlib.h> +#include <X11/extensions/Xrender.h> +#include <fontconfig/fontconfig.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main(int argc, char** argv) { + if (argc < 3) { + printf("xftwidth font string\n"); + return 1; + } + + Display *dpy; + XftFont *fn; + XGlyphInfo ext; + FcChar8 *str; + + char *name = argv[1]; + size_t len = strlen(argv[2]); +// len + 1?.. + str = (FcChar8*) malloc(len * sizeof(FcChar8) + 1); + + strncpy((char*)str, argv[2], len); + + dpy = XOpenDisplay(NULL); + fn = XftFontOpenName(dpy, 0, name); + + if (fn == NULL) { + printf("Font not found.\n"); + return 1; + } + + XftTextExtents8(dpy, fn, str, (int)len, &ext); + printf("%d\n", ext.width); + + free((void*)str); + return 0; +} diff --git a/xlibtest.c b/xlibtest.c new file mode 100644 index 0000000..670dcf6 --- /dev/null +++ b/xlibtest.c @@ -0,0 +1,59 @@ +/* + * Simple Xlib application drawing a box in a window. + * gcc input.c -o output -lX11 + */ + +#include <X11/Xlib.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main(void) +{ + Display *display; + Window window; + XEvent event; + char *msg = "Hello, World!"; + int s; + + /* open connection with the server */ + display = XOpenDisplay(NULL); + if (display == NULL) + { + fprintf(stderr, "Cannot open display\n"); + exit(1); + } + + s = DefaultScreen(display); + + /* create window */ + window = XCreateSimpleWindow(display, RootWindow(display, s), 10, 10, 200, 200, 1, + BlackPixel(display, s), WhitePixel(display, s)); + + /* select kind of events we are interested in */ + XSelectInput(display, window, ExposureMask | KeyPressMask); + + /* map (show) the window */ + XMapWindow(display, window); + + /* event loop */ + for (;;) + { + XNextEvent(display, &event); + + /* draw or redraw the window */ + if (event.type == Expose) + { + XFillRectangle(display, window, DefaultGC(display, s), 20, 20, 10, 10); + XDrawString(display, window, DefaultGC(display, s), 50, 50, msg, strlen(msg)); + } + /* exit on key press */ + if (event.type == KeyPress) + break; + } + + /* close connection to server */ + XCloseDisplay(display); + + return 0; +} |