Skip to content

Instantly share code, notes, and snippets.

View Experiment5X's full-sized avatar

Adam Spindler Experiment5X

View GitHub Profile
@Experiment5X
Experiment5X / mismatch.cpp
Created May 7, 2014 21:17
Example usage of std::mismatch algorithm.
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
vector<string> dogPeople = { "James", "Mary", "Tim", "Jane", "Greg" };
@Experiment5X
Experiment5X / Instruction2Bytecode.py
Created April 11, 2014 18:14
Convert an assembly instruction into its bytecode. It uses gas and otool, so this will only work on OS X, but it'd be pretty easy to modify it for linux.
# USAGE INSTRUCTIONS
# It's an interactive shell, where you have the following options...
# - Just type in an assembly instruction in Intel syntax, and it'll spit out the bytecode
# - Change the syntax to AT&T with the att command
# - Change the syntax back to Intel with the intel command
# - Quit with the q command
import os
import sys
import tempfile
import subprocess
@Experiment5X
Experiment5X / PowerOfTwo.java
Created March 25, 2014 12:54
I saw an interview question on reddit to check if a given number is a power of 2 in one line. Here's a solution in Java.
public static boolean isPowerOf2(int num)
{
return Math.log(num) / Math.log(2) == (double)(31 - Integer.numberOfLeadingZeros(num));
}
@Experiment5X
Experiment5X / Student.cpp
Created January 5, 2014 22:45
Just a simple project I made to demonstrate some concepts in C++. Here's the video where I teach this project: http://www.youtube.com/watch?v=NIoEVxe-rpk
//
// Student.cpp
// StudentInformationAnalyzer
//
// Created by Adam Spindler on 1/4/14.
// Copyright (c) 2014 Adam Spindler. All rights reserved.
//
#include "Student.h"
@Experiment5X
Experiment5X / Tweak.m
Created December 29, 2013 22:32
Change the secondary color theme in the music app on iOS 7 to be the aqua-blue color instead of that ugly pink.
#import <UIKit/UIKit.h>
@interface MAAppDelegate
@property (nonatomic,retain) UIWindow * window;
-(void)applicationDidFinishLaunching:(id)arg1;
@end
%hook MAAppDelegate
@Experiment5X
Experiment5X / remove_elements.cpp
Created December 7, 2013 17:34
The best way to remove elements from a vector, I got the concept from a video on MSDN by Stephan T. Lavavej about the associative containers in the stl.
template <typename T>
void remove_elements(vector<T> &vect, function<bool(T)> comparator)
{
auto newEnd = remove_if(vect.begin(), vect.end(), comparator);
vect.erase(newEnd, vect.end());
}
@Experiment5X
Experiment5X / Main.java
Created November 25, 2013 18:26
This program will solve any sudoku board that is in a text file. Numbers that aren't known should be represented as underscores and there shouldn't be any spaces. If there is more than one solution, then the first solution that is reached will be shown. Have fun.
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class Main
{
public static void main(String[] args)
{
JFileChooser fileDialog = new JFileChooser();
if (fileDialog.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
@Experiment5X
Experiment5X / MathFunctionLength.cpp
Last active December 27, 2015 17:49
This function will get the approximate length of a mathematical function if it were stretched into a straight line. This works by splitting the curve of the function up into a bunch of right triangles and then adding their hypotenuses together. The precision argument simply dictates the amount of triangles used. The more there are, the more accu…
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
double GetFunctionLength(double start, double end, function<double(double)> mathFunc, int precision)
{
if (precision < 1)
return 0;
@Experiment5X
Experiment5X / diabolo.py
Created September 1, 2013 21:28
TechGame programming challenge
import sys
def PrintDiaboloLine(centerLen, totalLen):
endLen = (totalLen - centerLen) / 2
print endLen * '.' + (centerLen * '@') + endLen * '.'
def PrintDiabolo(width, height, iteration):
if (iteration * 2) + 1 >= height:
PrintDiaboloLine(2, width)
return
@Experiment5X
Experiment5X / square.c
Created August 27, 2013 21:39
Square challenge solutions from TheTechGame.com
#include <stdio.h>
void PrintStarLine(int len)
{
for (int i = 0; i < len; i++)
printf("*");
printf("\n");
}
void PrintBodyLine(int len)