Skip to content

Instantly share code, notes, and snippets.

@loriopatrick
loriopatrick / Database.java
Created January 18, 2013 05:16
Something I always use when handling databases in Java. Has not been throughly tested.
import java.sql.*;
import java.util.Date;
import java.sql.Connection;
import java.util.ArrayList;
public class Database {
public Database(String server, String port, String user, String pass, boolean connect) {
this.server = server;
this.port = port;
this.user = user;
@loriopatrick
loriopatrick / prime.py
Last active December 11, 2015 18:19
is_prime
def is_prime (num):
to = int(pow(num, 1/2)) + 1
for x in range (2, to):
if num % x == 0:
return False
return True
@loriopatrick
loriopatrick / bruteforce.py
Last active December 11, 2015 18:19
Brute force password generator.
import string
from math import floor, ceil
CHARS = string.ascii_lowercase # + string.ascii_uppercase + string.digits
def gen_key (num, chars=CHARS):
"""
example with chars='ABC'
num | return
0 | A
@loriopatrick
loriopatrick / isnb10to13.py
Created January 27, 2013 08:58
A simple method to convert ISBN13 to ISBN10.
def isbn_13_to_10 (isbn):
count = 0
isbn = isbn[3:12]
for x in range(0, 9):
count += int(isbn[x]) * (10 - x)
z = (11 - (count % 11)) % 11
if (z == 10):
z = 'X'
return isbn + str(z)

Exam 1 Covers ch 9, 10, 20, 24 with book Chemistry A Molecular Approach

I am writing this without revision (because I'm lazy), so if something needs refining, there is an error, and/or there is a better way of explaining something, please mention it in the comments.

Chapter 9

Definitions

Electronegativity:

@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];
@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 / 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 / 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 / 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);