Skip to content

Instantly share code, notes, and snippets.

View ZachMassia's full-sized avatar

Zach Massia ZachMassia

  • MacEwen Petroleum Inc.
  • Ontario, Canada
View GitHub Profile
@ZachMassia
ZachMassia / redistester.rb
Created December 12, 2012 21:32
redis test class
require 'redis'
class RedisTester
def initialize
@redis = Redis.new
end
def set(key, value)
if redis_is_running?
#include <stdlib.h>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
struct profile
@ZachMassia
ZachMassia / MainWindow.java
Last active December 11, 2015 12:29
Move bot with up arrow
mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("UP"), "moveUp");
mainPanel.getActionMap().put("moveUp", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
bot.moveUp();
}
});
@ZachMassia
ZachMassia / MainWindow.java
Last active December 11, 2015 12:38
Proper movement with arrow key
// Bind up arrow to FinchController.moveUp()
mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("UP"), "moveUp");
mainPanel.getActionMap().put("moveUp", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (!isMoving[0]) {
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
@ZachMassia
ZachMassia / joy_axis_event.cpp
Last active December 11, 2015 20:29
Joystick axis event handler.
/**
* @brief Moves spaceship left/right.
*/
void Base::joy_axis(SDL_JoyAxisEvent *joy)
{
if (joy->which == 0 && joy->axis == 0) {
auto spaceship = &objects.at(1);
int stick_pos = joy->value;
float stick_mod = abs(stick_pos / 5000.0);
@ZachMassia
ZachMassia / Game1.cs
Last active December 11, 2015 21:18
XNA Update method
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
paddle.Update();
foreach (Ball ball in balls) {
ball.Update();
@ZachMassia
ZachMassia / main.cpp
Last active December 12, 2015 05:08
Thor Action Binders
#include <SFML/Graphics.hpp>
#include <Thor/Events.hpp>
#include <string>
#include <functional>
int main(int argc, char* argv[])
{
// The SFML Window
sf::RenderWindow mainWindow(sf::VideoMode(800, 600), "Thor Actions");
@ZachMassia
ZachMassia / gist:4991840
Created February 20, 2013 01:15
SFML Tutorials
http://www.sfml-dev.org/tutorials/2.0/
https://github.com/eXpl0it3r/SmallGameEngine
http://www.bromeon.ch/libraries/thor/tutorials.html
// Update all enemies, removing them if dead
enemies.erase(
std::remove_if(
enemies.begin(),
enemies.end(),
[&] (Sprite& enemy) -> bool {
enemy.update(dt);
// Kill if off screen
if (enemy.pos.x < 0) {
enemy.alive = false;
#0 std::string::compare(std::string const&) const() at /usr/lib/libstdc++.so.6:-1
#1 std::operator< <char, std::char_traits<char>, std::allocator<char> >() at /usr/include/c++/4.7.2/bits/basic_string.h:2566
#2 std::less<std::string>::operator()() at /usr/include/c++/4.7.2/bits/stl_function.h:236
#3 std::_Rb_tree<std::string, std::pair<std::string const, SDL_Texture*>, std::_Select1st<std::pair<std::string const, SDL_Texture*> >, std::less<std::string>, std::allocator<std::pair<std::string const, SDL_Texture*> > >::_M_lower_bound() at /usr/include/c++/4.7.2/bits/stl_tree.h:1097
#4 std::_Rb_tree<std::string, std::pair<std::string const, SDL_Texture*>, std::_Select1st<std::pair<std::string const, SDL_Texture*> >, std::less<std::string>, std::allocator<std::pair<std::string const, SDL_Texture*> > >::find() at /usr/include/c++/4.7.2/bits/stl_tree.h:1543
#5 std::map<std::string, SDL_Texture*, std::less<std::string>, std::allocator<std::pair<std::string const, SDL_Texture*> > >::find() at /usr/include/c++/4.7.2/bits