Skip to content

Instantly share code, notes, and snippets.

View Twinklebear's full-sized avatar

Will Usher Twinklebear

View GitHub Profile
@Twinklebear
Twinklebear / multi_iter.cpp
Created November 27, 2014 04:30
Simple silly multi iterator
#include <vector>
#include <algorithm>
#include <iostream>
template<class Iter>
class MultiIter {
std::vector<Iter> iters;
public:
using value_type = typename Iter::value_type;
@Twinklebear
Twinklebear / main.c
Last active August 29, 2015 14:04
Event handling snippet for Lorenzo_
#include <stdio.h>
#include <stdbool.h>
#include <SDL.h>
int main(int argc, char **argv){
if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError());
return 1;
}
@Twinklebear
Twinklebear / main.rs
Last active January 15, 2023 16:57
Messing about with Conjugate Gradient in Rust
extern crate sparse_matrix;
use sparse_matrix::{MatrixElement, SparseMatrix};
fn conjugate_gradient(matrix: &SparseMatrix, b: &Vec<f32>) -> Vec<f32> {
let mut r = b.clone();
let mut p = b.clone();
let mut x = Vec::from_elem(b.len(), 0f32);
let mut r_dot_r = [sparse_matrix::dot(&r, &r), 0f32];
let mut step = 0u;
@Twinklebear
Twinklebear / LoadingListener.java
Last active August 29, 2015 14:03
Minimal View Pager re-ordering crash
package will.testapp;
/**
* Fake listener to alert the adapter how many pages to be showing
*/
public interface LoadingListener {
public void loadingDone(int page, int pages);
}
@Twinklebear
Twinklebear / fragment.glsl
Last active August 29, 2015 14:00
Instanced textured quads, produces this render: https://i.imgur.com/opgHu0x.png
#version 330 core
//Sampler defaults to unit 0 which is where our texture is bound
uniform sampler2D tex;
in vec2 fuv;
out vec4 color;
void main(void){
@Twinklebear
Twinklebear / gist:9820162
Created March 27, 2014 22:11
stack trace explosion
1526-1549/what.whatandroid W/System.err﹕ java.io.IOException: unexpected end of stream
03-27 18:09:34.693 1526-1549/what.whatandroid W/System.err﹕ at libcore.net.http.FixedLengthOutputStream.close(FixedLengthOutputStream.java:58)
03-27 18:09:34.693 1526-1549/what.whatandroid W/System.err﹕ at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:818)
03-27 18:09:34.693 1526-1549/what.whatandroid W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
03-27 18:09:34.703 1526-1549/what.whatandroid W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
03-27 18:09:34.703 1526-1549/what.whatandroid W/System.err﹕ at api.soup.MySoup.login(MySoup.java:154)
03-27 18:09:34.703 1526-1549/what.whatandroid W/System.err﹕ at what.whatandroid.login.LoginTask.doInBackground(LoginTask.java:46)
03-27 18:09:34.703 1526-1549/what.whatandroid W/System.err﹕ at what.whatandroid.login.LoginTask.doInBackground(LoginTask
@Twinklebear
Twinklebear / 3_spheres.txt
Created March 22, 2014 21:28
Basic OpenCL ASCII ray cast rendering
| |
| |
| . |
| .0. |
| . |
| ..0.. |
| .@@@. |
| 0@@@0 |
| .@@@. |
| ..0.. |
@Twinklebear
Twinklebear / android_java.txt
Last active August 29, 2015 13:57
Header troubles
Request Properties:
User-Agent: WhatAndroid Android,
Response Headers:
null: HTTP/1.1 200 OK,
Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0,
CF-RAY: 10edc7c8b0c30129-SJC,
Connection: keep-alive,
Content-Type: text/html; charset=utf-8,
Date: Fri, 21 Mar 2014 23:03:01 GMT,
@Twinklebear
Twinklebear / main.cpp
Last active February 18, 2024 02:28
Example of render to texture with SDL2
#include <iostream>
#ifdef __linux__
#include <SDL2/SDL.h>
#elif defined(_WIN32)
#include <SDL.h>
#endif
const int WIN_WIDTH = 640;
const int WIN_HEIGHT = 480;
@Twinklebear
Twinklebear / main.cpp
Created October 30, 2013 20:54
Gamepad whatchamathingy. Requires SDL2. Should work with DInput and XInput, DInput only seems to be picked up as a joystick while XInput works as game controller and joystick.
#include <iostream>
#include <SDL2/SDL.h>
//It seems only XInput controllers are detected as game controllers
void xinputTest();
void dinputTest();
int main(int argc, char **argv){
if (SDL_Init(SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) != 0){
std::cout << "Init failed" << std::endl;