Skip to content

Instantly share code, notes, and snippets.

View BrooklinJazz's full-sized avatar

Brooklin Myers BrooklinJazz

View GitHub Profile
@BrooklinJazz
BrooklinJazz / counter.js
Last active November 21, 2018 13:34
React-Hook Counter
import React, { useState, Fragment } from "react"
export default function Counter(params) {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click Me
@BrooklinJazz
BrooklinJazz / hello_world.c
Created January 5, 2020 00:01
Hello World
#include <stdio.h>
int main()
{
printf("Hello world!\n");
}
@BrooklinJazz
BrooklinJazz / hello_void.c
Created January 5, 2020 00:27
hello_world_with_void
#include <stdio.h>
void main(void)
{
printf("Hello Void\n");
}
@BrooklinJazz
BrooklinJazz / hello_world_without_param.c
Created January 5, 2020 00:32
Hello World Without Void as a Param
#include <stdio.h>
int main()
{
printf("Hello world!\n");
}
@BrooklinJazz
BrooklinJazz / breaking_main.c
Created January 5, 2020 01:16
Breaking the main C convention
#include <stdio.h>
int BreakingConvention(void)
{
printf("I won't compile\n");
}
@BrooklinJazz
BrooklinJazz / solve_world_peace.js
Created January 25, 2020 23:27
simple guide to creating world peace
function solveWorldPeace(worldPeace) {
if (!worldPeace) {
worldPeace = true
}
}
@BrooklinJazz
BrooklinJazz / merge.js
Last active January 26, 2020 07:52
a documented example of the merge function in javascript
// 1. merge takes an already sorted left half and already sorted right half of the original array.
const merge = (left, right) => {
let resultArr = [];
let leftIndex = 0;
let rightIndex = 0;
// 2. merge crawls over these arrays creating a resulting array from the smallest values until either the left or right array is empty.
while ((leftIndex < left.length, rightIndex < right.length)) {
if (left[leftIndex] < right[rightIndex]) {
resultArr.push(left[leftIndex]);
@BrooklinJazz
BrooklinJazz / merge.c
Created January 26, 2020 00:01
a documented merge example in c
void merge(int arr[], int startIndex, int endIndex)
{
// 1. calculate the middle index
int midIndex = startIndex + ((endIndex - startIndex) / 2);
// 2. determine left array size
int leftArrSize = midIndex - startIndex + 1;
// 3. determine right array size
int rightArrSize = endIndex - midIndex;
// 4. initialize left and right arrays
@BrooklinJazz
BrooklinJazz / merge_sort.c
Created January 26, 2020 01:03
a documented example of merge sort in c
void mergeSort(int arr[], int leftIndex, int rightIndex)
{
// 1. If the array has < 1 element do nothing. otherwise:
if (leftIndex < rightIndex)
{
// 2. determine the middle index of the array
int midIndex = leftIndex + ((rightIndex - leftIndex) / 2);
// 3. mergeSort the left half of the array
mergeSort(arr, leftIndex, midIndex);
// 4. mergeSort the left half of the array
@BrooklinJazz
BrooklinJazz / machine.js
Last active February 9, 2020 02:03
Generated by XState Viz: https://xstate.js.org/viz
const initialActions = {
bad: "bad",
fearful: "fearful",
angry: "angry",
disgusted: "disgusted",
sad: "sad",
happy: "happy",
surprised: "surprised"
};