Skip to content

Instantly share code, notes, and snippets.

View joshkautz's full-sized avatar
🧠
Always Learning

Josh Kautz joshkautz

🧠
Always Learning
View GitHub Profile
@joshkautz
joshkautz / bubble_sort.c
Created March 2, 2016 18:52
C implementation of the Bubble Sort algorithm, which repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order.
#include<stdio.h>
int main() {
int a[50], n, i, j, temp = 0;
printf("Enter how many elements you want:\n");
scanf("%d", &n);
printf("\nEnter the %d elements:\n", n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
@joshkautz
joshkautz / linked_list.c
Created March 2, 2016 20:07
C implementation of the Linked List data structure, with add(), insert(), remove(), get(), size(), and print() functionality.
#include <stdio.h>
#include <stdlib.h>
#define LL_OK 0
#define LL_NOTOK 1
typedef struct ll_node {
void* value;
struct ll_node* next;
} ll_node;
@joshkautz
joshkautz / swap_list_element.c
Created September 3, 2016 18:58
Program written in C to swap specific elements in a list datatype
#include <stdio.h>
#include <stddef.h>
typedef struct _List {
struct _List *next;
int val;
} List;
enum {
SWAPSUCCESS,
@joshkautz
joshkautz / taskTypes.js
Created September 4, 2016 14:34
CodeFights - JavaScript code to determine which deadlines in an array are classified as being due 'today', 'upcoming', or 'later', based on the day they are expected to be completed.
function tasksTypes(deadlines, day) {
var resultArray = new Array(3);
var today = 0;
var upcoming = 0;
var later = 0;
for(i=0; i<deadlines.length; i++){
if(deadlines[i] <= day) {
today++;
}
@joshkautz
joshkautz / digitSum.js
Created September 4, 2016 14:35
CodeFights - JavaScript code to calculate the sum of all digits in an integer
function digitSum(n) {
var sum = 0;
var string = n.toString();
for(i=0; i < string.length; i++){
sum = sum + parseInt(string.substring(i, i+1));
}
return sum;
}
@joshkautz
joshkautz / emoji_animation.html
Last active September 8, 2016 04:31
JavaScript to randomly animate all the smiley face emojis supported in-browser, accompanied by relevant HTML display files.
<!DOCTYPE html>
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html, body {
height: 100%;
}
body {
datatype 'a Btree = Empty | Node of 'a * 'a Btree * 'a Btree;
fun member(x: 'a, ordering_relation: 'a * 'a -> bool, equality_relation: 'a * 'a -> bool, Empty) = false
| member(x: 'a, ordering_relation: 'a * 'a -> bool, equality_relation: 'a * 'a -> bool, Node(y, left, right)) =
if equality_relation(x,y) then true
else
if ordering_relation(x,y) then member(x, ordering_relation, equality_relation, left)
else member(x, ordering_relation, equality_relation, right);
fun insert(x, ordering_relation: 'a * 'a -> bool, equality_relation: 'a * 'a -> bool, Empty) = Node(x, Empty, Empty)
@joshkautz
joshkautz / dbDownload.py
Created September 27, 2016 15:57
Python script to download the contents of tables from a database to a local file, and backing up existing file if it exists.
#!/usr/bin/python
import sys
import os
from pathlib import Path
import sqlite3
from shutil import copyfile
# Takes the filename of the script, converts it to an absolute path.
# Then extracts the directory of that path, then changes into that directory.
@joshkautz
joshkautz / fishing.py
Last active September 28, 2016 21:16
Python 3.5.2 script to display a fishing animation
import os
import time
expander = {"n":"\n", "s": " ", "q": "~~~~~~"}
os.system(['clear','cls'][os.name == 'nt'])
animation = []
animation.append("""nnnnnnqqq""")
animation.append("""n/nnnnnqqq""")
animation.append("""n /n/nnnnqqq""")
@joshkautz
joshkautz / svgHueChanger.js
Last active September 30, 2016 14:42
JavaScript and jQuery to change the hue of an SVG
var modifier = Math.random()*360;
$( "#svgMain" ).click(function() {
var svg = document.getElementById("svgMain")
var allElements = svg.getElementsByTagName("*");
for(var i = 0; i < allElements.length; i++) {
var element = allElements[i];
console.log(element);
$(element).css({ fill: changeHue($(element).css('fill'),modifier)});
}