Skip to content

Instantly share code, notes, and snippets.

View chunkyguy's full-sized avatar

Sidharth Juyal chunkyguy

View GitHub Profile
@chunkyguy
chunkyguy / KingdomRush.c
Created April 28, 2012 03:44
Dead virgin code; couldn't even compile once :(
#include <iostream.h>
#define N_MAX 2048
typedef struct{
int num;
int easyDone;
int easyStar;
int hardDone;
int hardStar;
@chunkyguy
chunkyguy / createimp.c
Created July 1, 2012 10:35
Create ObjectiveC implementation file from interface file.
/*
Input:
- (void)viewWillDisappear:(BOOL)animated;
Output:
- (void)viewWillDisappear:(BOOL)animated{
[handler_ viewWillDisappear:animated];
}
*/
@chunkyguy
chunkyguy / DebugAlert.h
Created July 24, 2012 00:16
Debugging with UIAlertViews
#define POP_ALERT(title, msg) [[[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]autorelease] show]
/*
Usage:
POP_ALERT(@"Title Here", @"Message Here");
*/
@chunkyguy
chunkyguy / twoChecWins.m
Created August 1, 2012 15:16
The two checkWin methods accomplish the same task
/** Logic 1 */
-(BOOL)funcOfBase:(int)b multiple:(int)n{
return ((_slots[b]==_aType) && (_slots[b+n*1]==_aType) && (_slots[b+n*2])==_aType);
}
-(BOOL)checkWin{
int bases[5] = {0, 1, 2, 3, 6};
int multiples[5][4] = {
{1, 3, 4, 0},
{3, 0, 0, 0},
if(troop_position == 4){
for(int possible_position = 0; possible_position < 9; possible_position++){
if(_slots[possible_position] == -1){
availPos[troop_number][available_position[troop_number]++] = possible_position;
}
}
}else{
for(int possible_position = 0; possible_position < 3; possible_position++){
if(_slots[_nextPossiblePositions[troop_position][possible_position]] == -1){
availPos[troop_number][available_position[troop_number]++] = _nextPossiblePositions[troop_position][possible_position];
@chunkyguy
chunkyguy / iOS_OpenGL_template.c
Created August 16, 2012 20:37
Apple OpenGL template for iOS uses two sets of enums
/*
At create setup stage
*/
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0));
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));
/*
At binding stage
@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"