Skip to content

Instantly share code, notes, and snippets.

View LightningStalker's full-sized avatar

LightningStalker

View GitHub Profile
@LightningStalker
LightningStalker / argvdump.c
Created August 25, 2017 21:47
Gisting some things over from Pastebin
/* argvdump.c
* Dumps all command line arguments
* Useful for debugging programs that call other programs
* Just create a symlink with the name of your target application.
* The Lightning Stalker 2013
*/
#include <stdio.h>
int main (int argc, char **argv)
@LightningStalker
LightningStalker / cyph.c
Last active March 28, 2018 08:53
Simple Caesar cypher algorithm
/*
* Simple Caesar cypher algorithm
* Preserves case and non-alpha characters
* by The Lightning Stalker
*/
#include <stdio.h>
#include <ctype.h>
#define ALPHA 26 // letters in alphabet
@LightningStalker
LightningStalker / gridcalc.c
Last active August 25, 2017 21:49
Computes wavelength of incident light
/*
* Computes wavelength of incident light
* Formulas used:
* Arctangent - atan(c / a) - thanks Cyparagon
* Diffraction grating formula - nλ = d sin(ϴ)
* Pythagorean theorem - a² + b² = c²
* The Lightning Stalker 2013
*/
#include <math.h>
@LightningStalker
LightningStalker / picloops.c
Created August 25, 2017 21:51
Calculate PIC microcontroller timing loops of 1-4 stages using given inner loop overhead
/* compile with "gcc -Wall -opicloops picloops.c -lm"
*
* picloops.c - Calculate PIC microcontroller timing loops of 1-4 stages
* using given inner loop overhead
*
* Time in seconds and clock speed in MHz shall be specified on the
* command line in any order. For instance
* $ ./picloops 4 60
*
* Loosely based on picasm's pic loop calculator
@LightningStalker
LightningStalker / price.c
Created August 25, 2017 21:52
Economics simulator
#include <stdio.h>
int main (int argc, char **argv)
{
int price = 1;
while(1)
{
printf("Price has gone up from $%i to ", price);
price++;
printf("$%i\n", price);
@LightningStalker
LightningStalker / quine.c
Created August 25, 2017 21:54
Self-reproducing program
#include <stdio.h>
int main() { char *a,*s,*q; printf(s="int main() { char *a,*s,*q; printf(s=%s%s%s, q=%s%s%s%s,s,q,q,a=%s%s%s%s,q,q,q,a,a,q); return 0; }",q="\"",s,q,q,a="\\",q,q,q,a,a,q); return 0; }
@LightningStalker
LightningStalker / rc.c
Created August 25, 2017 22:30
Not sure what I was doing with this one, but here it is
#include <stdio.h>
int main (int argc, char **argv)
{
float i = 63.2, j = 63.2;
int t;
for (t = 0; t < 5; t++)
{
printf("%0.1f", j);
@LightningStalker
LightningStalker / resetusb.c
Created August 25, 2017 22:32
Resets the USB busses, makes devices reattach without unplugging and plugging back in
#include <stdio.h> // requires usblib
#include <usb.h> // compile with #gcc -Wall -o resetusb resetusb.c -lusb
int main(void)
{
struct usb_bus *busses;
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
@LightningStalker
LightningStalker / rpms.c
Last active July 8, 2024 09:21
Calculates RPMs based on input from the keyboard
/*
* RPM calculator
* Takes input from the keyboard
* Uses the ncurses library
* by The Lightning Stalker
*
* needs a rewrite to use clock_gettime(CLOCK_TAI, ...)
*
* Compile with gcc -Wall -o rpms rpms.c -lcurses
*/
@LightningStalker
LightningStalker / seriesw.c
Created August 25, 2017 22:35
Find wattage dissipated by potentiometer and series resistor
/* compile with "gcc -Wall -oseriesw seriesw.c -lm"
*
* Steps through possible pot settings and finds the wattage dissipated
* by the pot and a series resistor.
* - by The Lightning Stalker 2014
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>