Skip to content

Instantly share code, notes, and snippets.

View benwaffle's full-sized avatar
🍝
best spaghetti in town

Ben Iofel benwaffle

🍝
best spaghetti in town
View GitHub Profile
@benwaffle
benwaffle / SleepSort.java
Last active December 27, 2015 19:09
SleepSort for java 8
public class SleepSort {
public static void main(String[] args) {
for (String arg : args) {
int time = Integer.parseInt(arg);
new Thread(() -> {
try {
Thread.sleep(time*10);
} catch (Exception e) {e.printStackTrace();}
@benwaffle
benwaffle / MathReflection.java
Created December 17, 2013 16:41
Create an instance of the Math class
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
public class MathReflection {
public static void main(String[] args) throws SecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
Constructor<?> ctor = Math.class.getDeclaredConstructors()[0];
ctor.setAccessible(true);
Math mathinstance = (Math) ctor.newInstance();
System.out.println(mathinstance);
@benwaffle
benwaffle / Crypto.java
Created March 6, 2014 05:56
Powerschool Crypto for Login
public class Crypto {
private static String sStringToHMACMD5(String s, String keyString) {
String sEncodedString = null;
try {
javax.crypto.spec.SecretKeySpec key = new javax.crypto.spec.SecretKeySpec((keyString).getBytes("UTF-8"), "HmacMD5");
javax.crypto.Mac mac = javax.crypto.Mac.getInstance("HmacMD5");
mac.init(key);
byte[] bytes = mac.doFinal(s.getBytes("ASCII"));
@benwaffle
benwaffle / HSH_IRC.md
Last active August 29, 2015 14:00 — forked from kjpark/HSH_IRC.md

For those of you HS hackers familiar with IRC, go and join the conversation at #hshackers on freenode

##What is this IRC you speak of? Internet Relay Chat is an slightly older form of communication, but it is still widely used today. Many developer communities use these channels to quickly get help and/or discuss projects.

##Why join the convo? Because the HSH community is a group of brilliant individuals that needs answers and feedback - lots of it, and fast!

##How to get in on the convo The first thing that you will need is an IRC client, it'll connect you to all the networks and whatnot. A few popular clients:

@benwaffle
benwaffle / xor.c
Last active August 29, 2015 14:00
xor flip case
#include <ctype.h>
char flip(char in) {
if (isalpha(in))
if (isupper(in))
return tolower(in);
else
return toupper(in);
return in;
}
@benwaffle
benwaffle / CrashJVM.java
Created May 10, 2014 19:01
CrashJVM.java
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class CrashJVM {
public static void main(String[] args) throws Exception {
Field privUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
privUnsafe.setAccessible(true);
Unsafe theUnsafe = (Unsafe) privUnsafe.get(null);
theUnsafe.freeMemory(1);
@benwaffle
benwaffle / write-ret.c
Last active August 29, 2015 14:01
Writing over the return address
#include <stdio.h>
void func(){
int *ret; // a local var in stack frame
ret = &ret+2; // +1 for the int* and +1 for saved ebp
*ret += 12; // ret addr += 12 (get from disassembly)
}
int main(int argc, char *argv[]) {
func();
@benwaffle
benwaffle / reassurance_sort.c
Created May 28, 2014 18:41
Reassurance Sort
#include <stdlib.h>
int compare(const void *a, const void *b) {
return *(int*)a - *(int*)b;
}
void reassurance_sort(int *nums, int len){
qsort(nums, len, sizeof(int), compare);
qsort(nums, len, sizeof(int), compare);
}
@benwaffle
benwaffle / Makefile
Last active August 29, 2015 14:03
simple torrent downloader
CC=g++
CFLAGS=
LDFLAGS=-ltorrent-rasterbar -lpthread -lboost_system
all:
$(CC) $(CFLAGS) $(LDFLAGS) -o test test.cpp
@benwaffle
benwaffle / Makefile
Created July 13, 2014 15:29
Calling C++ from C
cpp:
g++ -shared -fPIC -o libcppcode.so cppcode.cpp
c:
gcc -L. -lcppcode -o main main.c