Skip to content

Instantly share code, notes, and snippets.

View chunkyguy's full-sized avatar

Sidharth Juyal chunkyguy

View GitHub Profile
@chunkyguy
chunkyguy / sfml_2.cpp
Created August 21, 2012 14:26
SFML 2.0 boilerplate
int main (int argc, const char * argv[]){
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
// Load a sprite to display
sf::Texture texture;
if (!texture.loadFromFile(resourcePath() + "cute_image.jpg"))
return EXIT_FAILURE;
sf::Sprite sprite(texture);
@chunkyguy
chunkyguy / Electricity.cpp
Created August 22, 2012 12:13
How to generate electricity
/*
Electricity:
resolution_ = 0; means straight line
pointA_, pointB_; are vec4s
*/
void ElectricCurrent::createVertexData(){
int tfloats = (2+resolution_) * 4; //num_points * num_floats_per_point
GLfloat data[tfloats];
int atIndx = 0;
@chunkyguy
chunkyguy / obfuscated.c
Created August 23, 2012 03:44
height of stupidity
/*
This piece of shit that I wrote does one simple task: linearly interpolate between 0.0 and 1.0 for the value 'res'.
This is a sample run:
$ ./mix 1
0: 0.500000
$ ./mix 2
0: 0.333333
1: 0.666667
$ ./mix 3
0: 0.250000
@chunkyguy
chunkyguy / SJViewController.m
Created September 15, 2012 05:41
This code is leaking !!
//
// SJViewController.m
// TestSkybox
//
// Created by Sidharth Juyal on 22/06/12.
// Copyright (c) 2012 whackylabs. All rights reserved.
//
#import "SJViewController.h"
@chunkyguy
chunkyguy / Exception.cpp
Created October 13, 2012 08:16
Exception Handling C vs C++
/*
What: Exception using throw and jmp/longjmp
Author: Sid
Note: Test run with 3 cases
1: x(10), y(2) : Returns 2
2: x(10), y(0) : Catch exception DIVIDE_EXCP, prints error and quit
3: x(10), y(-2) : Catch exception NEG_EXCP, does nothing
*/
#include <iostream>
@chunkyguy
chunkyguy / lpf.cpp
Created November 6, 2012 00:07
largest prime factor - unoptimized
#include <iostream>
#include <cmath>
#include <cstring>
bool debug;
bool isFactor(long double n, long double f){
long double i = 1.0;
long double m = f * i;
while(m <= n){
@chunkyguy
chunkyguy / gist:5082285
Created March 4, 2013 13:37
Line segment intersection test
// Test for two line segments intersection
// sid@whackylabs.com
// Inspired from:
// theory: http://www.bryceboe.com/2006/10/23/line-segment-intersection-algorithm/
// source: http://www.bryceboe.com/wordpress/wp-content/uploads/2006/10/intersect.py
#include <iostream>
template<typename T>
/*
sid@whackylabs.com
Tool to test collision detection using Grapher.app
Create formatted data.
Input: cd.in
0.000000 320.000000 194.204971 -60.418026 244.204971 -10.418026
0.000000 320.000000 194.249619 -60.418026 244.249619 -10.418026
0.000000 320.000000 194.294266 -60.418026 244.294266 -10.418026
@chunkyguy
chunkyguy / gist:5206358
Created March 20, 2013 17:01
C++ pointer to member function
// Using std::function for callback
#include <iostream>
#include <utility>
class Client;
// Calculator server
class Server{
public:
typedef void (Client::*CB)(int result);
@chunkyguy
chunkyguy / gist:5253727
Created March 27, 2013 12:08
This code demonstrates a way to broadcast messages to many listeners. I'm scrapping this code I worked on for few hours. Why? Because for now I'm going forward with one global event dispatcher. Right now on iDevices it doesn't makes any sense to buffer the events, as the OS already buffers them. Maybe someday I'll return to something similar.
//
// EventLoop.h
// HideousGameEngine
//
// Created by Sid on 27/03/13.
// Copyright (c) 2013 whackylabs. All rights reserved.
//
#ifndef __HideousGameEngine__EventLoop__
#define __HideousGameEngine__EventLoop__