Skip to content

Instantly share code, notes, and snippets.

View j-mcc1993's full-sized avatar

James McCullough j-mcc1993

  • Bay Area & San Diego, CA
View GitHub Profile
@j-mcc1993
j-mcc1993 / Arduino_NES_Controller.ino
Last active January 1, 2016 21:19
Arduino Sketch that handles serial communication between NES controller and Arduino
int latch = 7; //signals controller to latch button states
int pulse = 5; //toggle to shift out button states
int data = 9; //data in line
int data_byte; //byte that stores button states
int count[] = {0,0,0,0,0,0,0,0}; //each value stores 1 or 0 indicating whether a key is currently pressed
char keys[] = {'a','b','s','d','u','j','l','r'}; //keyboard keys to be pressed
int tempbit; //iterates over the data_byte to grab each button's state
void setup() {
pinMode(latch, OUTPUT);
@j-mcc1993
j-mcc1993 / Quick_Reddit_Scraper.py
Last active January 1, 2016 21:39
A script that traverses a supplied number of links on the "hot" page of the supplied subreddit and downloads all posted images (with some corner cases).
import urllib.request, os, praw, datetime
from bs4 import BeautifulSoup
from sys import argv
script, sub, lim = argv
r = praw.Reddit(user_agent = 'RedditScraper1.0 by /u/I_Am_Treebeard')
subreddit = r.get_subreddit(sub)
directory = '/Users/admin/desktop/%s (%s)' % (sub, datetime.date.today())
if not os.path.exists(directory): os.makedirs(directory)
collectpath = directory + '/All_Pictures'
@j-mcc1993
j-mcc1993 / Arduino_SNES_Controller.ino
Last active January 1, 2016 23:28
Arduino Sketch that handles serial communication between SNES controller and Arduino board.
int latch = 7; //signals controller to latch button states
int pulse = 5; //toggle to shift out button states
int data = 9; //data in line
int data_byte; //byte that stores button states
int count[] = {0,0,0,0,0,0,0,0,0,0,0,0}; //each value stores 1 or 0 indicating
//whether a key is currently pressed
char keys[] = {'a','b','s','d','u','j','l','r','w','e','t','y'}; //keyboard keys to be pressed
int tempbit; //iterates over the data_byte to grab each button's state
void setup() {
pinMode(latch, OUTPUT);
@j-mcc1993
j-mcc1993 / Expect_FTP.tcl
Last active August 29, 2015 14:03
Expect Script that automatically grabs Ephemeris data from server via Telnet
#!/usr/bin/expect
set env(TERM) no-resize-vt100
set timeout 15
set START_DATE "2014-Jun-26 03:00"
set END_DATE "2014-Jun-26 03:20"
set TIME_STEP "1m"
set M_BODY 301
spawn telnet horizons.jpl.nasa.gov 6775
expect "Horizons> " {send "load JMCCM-1\r"}
expect "Horizons> " {send "$M_BODY\r"}
@j-mcc1993
j-mcc1993 / Fractal.java
Created June 27, 2014 05:39
Java Fractal Image Generator
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
public class Fractal {
public static void main(String[] args) {
int width = 2048/2;
int height = 1536/2;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
@j-mcc1993
j-mcc1993 / LED_BYTE_CALCULATOR.ino
Created June 27, 2014 05:52
Arduino sketch that turns 8 LEDs into a byte adder using two buttons.
const int pot = A15;
const int pushButton = 22;
const int pushButton2 = 27;
int bitList[8] = {
};
int pinSet[] = {
13,11,9,7,5,3,14,16};
byte sensorValue = 0;
int op1;
int op2;
@j-mcc1993
j-mcc1993 / Telnet_Ephemeris.sh
Created June 27, 2014 05:55
Short Shell Script that runs expect script to grab Ephemeris data and stores output into files with unique names.
#!/bin/sh
EPHEMFILE=Ephem_Data_$(date "+%Y-%m-%d|%H-%M-%S").txt
OUTFILE=Output_$(date "+%Y-%m-%d|%H-%M-%S").txt
./expect_ftp.sh >/dev/null
READ=$(ls|grep .*\.15)
cat $READ > $OUTFILE
cat $OUTFILE | sed -n '/$$SOE/,/$$EOE/p' | sed -e 's/\$.*//' -e '/^$/ d' > $EPHEMFILE
cat "$EPHEMFILE"
rm $READ
@j-mcc1993
j-mcc1993 / pyserial.py
Created June 27, 2014 05:56
Testing out pySerial library to communicate serially with Arduino over USB.
import serial, time
ser = serial.Serial('/dev/cu.usbmodem411', 9600)
while True:
bin = bytes(chr(5), encoding = 'ascii')
print(bin)
ser.write(bin)
time.sleep(2)
@j-mcc1993
j-mcc1993 / imgur_test.py
Last active July 16, 2020 17:12
Reddit Scraper 2.0 with Imgur API
#!/usr/local/bin/python3.5
import datetime
import os
import praw
import pprint
import urllib2
from imgurpython import ImgurClient
from sys import argv
################################################################################
################################################################################
## ------------------------------------------------------------------------ ##
## | The PKA podcast downloader! Downloads all the PKA podcasts directly to | ##
## | external drive. | ##
## ------------------------------------------------------------------------ ##
## ------------------------------------------------------------------------ ##
## | | ##
## | ####### ## ## ### ###### | ##
## | ## ## ## ## ## ## ######## | ##