Skip to content

Instantly share code, notes, and snippets.

View MichaelSnowden's full-sized avatar

Michael Snowden MichaelSnowden

View GitHub Profile
#include <stdio.h>
#include <math.h>
#define LOWER 0
#define UPPER 20
#define RADIUS 1
int factorial(int n)
{
if (n == 0)
@MichaelSnowden
MichaelSnowden / gist:9480644
Last active August 29, 2015 13:57
Why doesn't glDrawElements work here?
//
// ViewController.h
// ScrewingAround
//
// Created by Michael Snowden on 3/9/14.
// Copyright (c) 2014 Michael Snowden. All rights reserved.
//
#import <UIKit/UIKit.h>
@MichaelSnowden
MichaelSnowden / gist:9648757
Last active August 29, 2015 13:57
This algorithm will generate the triangulated indices for an n-cube, that is a cube of n dimension. If the dimension is 0 or 1, it'll break. If it's 2, it'll give 0, 1, 3, 2, 3, 0 because it's a square and the vertices are {-1, -1}, {1, -1}, {-1, 1}, {1, 1}
#define CUBE_DIMENSION 4
GLushort *indices;
GLuint numIndices;
int main()
{
numIndices = 24 * 6;
indices = malloc(sizeof(GLushort) * numIndices);
int powers[CUBE_DIMENSION];
NSString *pattern = @"[A-Z][a-z]?\\d*|(?<!\\([^)]*)\\(.*\\)\\d+(?![^(]*\\))";
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:pattern
options:0
error:nil];
NSArray *tests = [[NSArray alloc ] initWithObjects:@"Ca3(PO4)2", @"HCl", @"CaCO3", @"ZnCl2", @"C7H6O2", @"PtCl2(NH3)2", @"Co3(Fe(CN)6)2", nil];
for (NSString *testString in tests)
{
NSLog(@"Testing: %@", testString);
NSArray *myArray = [regex matchesInString:testString options:0 range:NSMakeRange(0, [testString length])] ;
@MichaelSnowden
MichaelSnowden / vortexShader.fsh
Created September 6, 2014 21:36
vortexShader.fsh from WWDC 2014 SpriteKit demo https://developer.apple.com/videos/wwdc/2014/#411
void main(void)
{
float currTime = u_time;
vec2 uv = v_tex_coord;
vec2 circleCenter = vec2(0.5, 0.5);
vec3 circleColor = vec3(0.8, 0.5, 0.7);
vec3 posColor = vec3(uv, 0.5 + 0.5 * sin(currTime)) * circleColor;
float illu = pow(1. - distance(uv, circleCenter), 4.) * 1.2;
@MichaelSnowden
MichaelSnowden / Operator.h
Last active August 29, 2015 14:06
This is an Operator class. Just an idea I had for making operators way too object-oriented
#ifndef Truth_Operator_h
#define Truth_Operator_h
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <functional>
using namespace std;
@MichaelSnowden
MichaelSnowden / UITextField+Cursor.h
Last active August 29, 2015 14:06
How to move the UITextField cursor
#import <UIKit/UIKit.h>
@interface UITextField (Cursor)
- (void)offsetCursorBy:(int) n;
@end
//
// Cube.h
// OpenGL
//
// Created by Michael Snowden on 11/15/14.
// Copyright (c) 2014 MichaelSnowden. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <OpenGLES/ES1/glext.h>
<?xml version="1.0" encoding="UTF-8"?>
<inspections version="1.0">
<option name="myName" value="LoD" />
<inspection_tool class="AbstractBeanReferencesInspection" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="AccessStaticViaInstance" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="AndroidDomInspection" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="AndroidElementNotAllowed" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="AndroidLintAaptCrash" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="AndroidLintAccidentalOctal" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="AndroidLintAdapterViewChildren" enabled="false" level="WARNING" enabled_by_default="false" />
package com.michaelsnowden.generated;
import com.google.common.base.Joiner;
import com.michaelsnowden.js2j.Javascript;
import com.michaelsnowden.js2j.JavascriptObject;
public class $ extends JavascriptObject {
protected String varName;