Skip to content

Instantly share code, notes, and snippets.

@loriopatrick
loriopatrick / WebCache.java
Created June 2, 2014 19:35
A simple method to cache web requests.
import java.io.*;
import java.net.URL;
import java.net.URLEncoder;
/**
* @author Patrick Lorio
*/
public class WebCache {
public static InputStream GetWeb(String url) throws IOException {
File file = new File("cache/" + URLEncoder.encode(url, "UTF-8"));
@loriopatrick
loriopatrick / macros.c
Created May 26, 2014 23:35
C is awesome!
#include <stdio.h>
#include <stdlib.h>
#define call(VAR, METHOD, ...) (VAR)->METHOD(VAR, __VA_ARGS__)
#define with(TYPE, NAME, VALUE, BODY) {TYPE NAME = VALUE; BODY free(NAME);}
void flyImpl(void* rocket, int x_fore, int y_fore) {
printf("Applying force (%i, %i)\n", x_fore, y_fore);
}
@loriopatrick
loriopatrick / Makefile
Created May 20, 2014 20:22
A simple makefile.
CC=clang
FLAGS=-Wall -g
INCLUDE=-I./include
EXEC=out/program
SRC=$(wildcard src/*.c)
OBJ=$(SRC:src/%.c=obj/%.o)
run: setup link
./$(EXEC)
@loriopatrick
loriopatrick / c_is_awesome.c
Created May 20, 2014 20:18
I think I'm going to get more into C.
#include <stdio.h>
typedef struct {
float x;
float y;
char* name;
} Player;
typedef void (*PlayerCommand)(Player* player);
@loriopatrick
loriopatrick / ipUpdate.js
Created March 20, 2014 20:08
Send an email to an admin when the public ip changes.
var exec = require('child_process').exec;
function getIp(callback) {
exec('wget -qO- http://ipecho.net/plain ; echo', function (error, stdout, stderror) {
if (error) {
callback(error, null);
return;
}
var ip = stdout.replace('\n', '');
@loriopatrick
loriopatrick / Listener.java
Created February 19, 2014 22:12
Get audio input
package audiosource;
import javax.sound.sampled.*;
import java.io.IOException;
import java.nio.ByteBuffer;
public class Listener {
public Listener() throws LineUnavailableException {
audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, sampleRate, sampleSize,
channels, sampleSize / 8 * channels, sampleRate, true);
@loriopatrick
loriopatrick / sdl2_opengl_example.c
Last active December 30, 2015 05:19
A simple SDL2/OpenGL demo
#include <stdio.h>
#include <stdlib.h>
#include "SDL2/SDL.h"
#include "SDL2/SDL_opengl.h"
int main(int argc, char** argv) {
// init
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* window = SDL_CreateWindow("SDL2/OpenGL Demo", 0, 0, 640, 480, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
@loriopatrick
loriopatrick / Physics Exam 1 Study Guide.md
Last active December 26, 2015 11:19
My study guide for ch23-25 in physics.

Physics Exam 1 Study Guide

Coulomb's Law / Electric Field ch.23

equation (units= N)

@loriopatrick
loriopatrick / factor.c
Created February 15, 2013 01:18
An attempt to factor numbers using binary multiplication and bitwise operators.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
// note, in binary 0x80 = [10000000], 0x7F = [011111111]
#define CHARS(BITS) (int)(((BITS) - (((BITS) - 1) % 8)) / 8) + 1
#define BIT(DATA, POS) ((DATA[(int)((POS) / 8)] & (0x80 >> ((POS) % 8))) != 0)
#define SET0(DATA, POS) DATA[(int)((POS) / 8)] &= (0x7F >> ((POS) % 8) | 0x7F << (8 - ((POS) % 8)))
@loriopatrick
loriopatrick / ezcrpyt.c
Created February 14, 2013 01:02
Something I created a long time ago while familiarizing myself with bitwise operators.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void encrypt (char * msg, int msg_len, char * key, int key_len) {
int i, p;
char c;
for (i = 0; i < msg_len; i++) {
c = msg[i];