Skip to content

Instantly share code, notes, and snippets.

View Experiment5X's full-sized avatar

Adam Spindler Experiment5X

View GitHub Profile
@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 / 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 / RvalueReference.cpp
Created May 14, 2014 02:07
For future me, when I forget how this works.
#include <iostream>
#include <algorithm>
using namespace std;
class Matrix
{
public:
// constructor
Matrix(int width, int height) :
@Experiment5X
Experiment5X / PyhtonStringMultiply.cpp
Last active August 29, 2015 14:01
Python-like string multiplication... probably not a good idea to actually use though.
#include <iostream>
#include <string>
std::string operator *(std::string str, int n)
{
std::string toReturn = "";
if (n <= 0)
return toReturn;
for (int i = 0; i < n; i++)
@Experiment5X
Experiment5X / GitCVSComments.py
Created October 21, 2014 02:10
Put CVS comments at the top of files in your git repo. I made this because my CS class at RIT requires you to use CVS for these comments, and I would much rather use git.
import sys
import os
import re
import subprocess
class CommitInfo:
date = ''
timestamp = ''
message = ''
@Experiment5X
Experiment5X / C++ProgramBug.md
Last active August 29, 2015 14:09
An interesting bug I found in one of my programs

Today I came across a bug in my project that originally had me thinking I was experiencing yet another bug in Qt Creator, but it turns out I was wrong. In my project I had three main files:

ClipboardSynchronizer.h
ClipboardSynchronizer.cpp
main.cpp

The buggy version of my code in main.cpp was this:

@Experiment5X
Experiment5X / xboxavatar.rb
Created February 3, 2015 05:36
Gets a list of all the avatar items for a specified Xbox360 game. The program requires a title id for each game which is an 8-digit id that can be found in the URL of game's webpage on xbox.com
require 'rubygems'
require 'nokogiri'
require 'open-uri'
if ARGV.length != 1
puts "Usage: xboxavatar title-id"
exit
end
begin
@Experiment5X
Experiment5X / gist:4166386
Created November 29, 2012 02:26
Sick Drawing Stuff
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DrawingStuff
{
public partial class Form1 : Form
{
public Form1()
{
@Experiment5X
Experiment5X / Word2Element.rb
Last active December 15, 2015 12:09
Word2Element will convert a string of text into elements from the periodic table whose symbols make up the string of text. Of course not all strings of text can be made into an elemental representation, so if it's impossible to convert the application will spit out "Not possible"
Element = Struct.new(:symbol, :name)
elements = []
def word2Element(w, builder, elements)
if w.length == 0
return builder
end
# check for 1 char symbol
#include <stdio.h>
#include <stdlib.h>
#include <sys/queue.h>
struct _Student
{
LIST_ENTRY(_Student) entries;
char name[20];
int age;
float gpa;