Skip to content

Instantly share code, notes, and snippets.

View galek's full-sized avatar
🧭
I'm ready for new discoveries

Nikolay Galko galek

🧭
I'm ready for new discoveries
View GitHub Profile
@jeetsukumaran
jeetsukumaran / custom_iterator.cpp
Created February 18, 2010 02:33
Sample C++/STL custom iterator
// Sample custom iterator.
// By perfectly.insane (http://www.dreamincode.net/forums/index.php?showuser=76558)
// From: http://www.dreamincode.net/forums/index.php?showtopic=58468
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cassert>
@od0x0
od0x0 / gist:965399
Created May 10, 2011 21:17
How I Load a .ogg into OpenAL Using stb_vorbis
typedef struct{
ALuint ID;
stb_vorbis* stream;
stb_vorbis_info info;
ALuint buffers[2];
ALuint source;
ALenum format;
@jesperdj
jesperdj / vecmath.hpp
Created June 10, 2011 17:51
Simple vector math classes with SSE-optimized implementation (C++).
/*
* Copyright 2011 Jesper de Jong
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
// Tests each segment for a hit. All calculations are done in screen space pixel coordinates
bool CollisionPath::hitTest(const ViewportPosition &selection_position) const
{
const Vector2 &mouse_pixel_pos = selection_position.getPixelPosition();
const Viewport &viewport = selection_position.getViewport();
const Camera &camera = viewport.getCamera();
const WorldLayer &layer = *getLayer();
for(auto iter = anchors.begin(); iter != anchors.end()-1; ++iter) {
const Vector2 &segment_begin =
@Novum
Novum / gist:1200562
Created September 7, 2011 13:31
Fast SSE pow for range [0, 1]
// Fast SSE pow for range [0, 1]
// Adapted from C. Schlick with one more iteration each for exp(x) and ln(x)
// 8 muls, 5 adds, 1 rcp
inline __m128 _mm_fastpow_0_1_ps(__m128 x, __m128 y)
{
static const __m128 fourOne = _mm_set1_ps(1.0f);
static const __m128 fourHalf = _mm_set1_ps(0.5f);
__m128 a = _mm_sub_ps(fourOne, y);
__m128 b = _mm_sub_ps(x, fourOne);
@Novum
Novum / gist:1272928
Created October 8, 2011 21:46
world position from depth buffer value
// Reconstruct worldspace depth value from z/w depth buffer
float depth = -(z_near * z_far) / (zbuffer_depth * (z_far - z_near) - z_far);
// Compute screenspace coordinate of pixel
float2 screenspace = (float2(pixel.xy) / float2(viewport_size.xy)) * 2.0f - 1.0f;
// Get direction of ray from camera through pixel
float3 ray_direction = normalize(camera_forward + camera_right * screenspace.x - camera_up * screenspace.y);
// Reconstruct world position from depth: depth in z buffer is distance to picture plane, not camera
function getLine(offset) {
var stack = new Error().stack.split('\n'),
line = stack[(offset || 1) + 1].split(':');
return parseInt(line[line.length - 2], 10);
}
global.__defineGetter__('__LINE__', function () {
return getLine(2);
});
@omolina
omolina / MongoDB update all matching.js
Created September 6, 2012 22:17 — forked from sym3tri/MongoDB update all matching.js
How to update a single field in a MongoDB collection for all documents matching a specific criteria
// FROM: http://www.mongodb.org/display/DOCS/Updating#Updating-update%28%29
//
// db.collection.update( criteria, objNew, upsert, multi )
// criteria - query which selects the record to update;
// objNew - updated object or $ operators (e.g., $inc) which manipulate the object
// upsert - if this should be an "upsert"; that is, if the record does not exist, insert it
// multi - if all documents matching criteria should be updated
//
// SQL VERSION:
// UPDATE myTable SET dateField = '2011-01-01' WHERE condField = 'condValue'
@hubgit
hubgit / list-files-in-folder.js
Created September 20, 2012 11:20
List all files in a folder (Google Apps Script)
function listFilesInFolder() {
var folder = DocsList.getFolder("Maudesley Debates");
var contents = folder.getFiles();
var file;
var data;
var sheet = SpreadsheetApp.getActiveSheet();
sheet.clear();
@printesoi
printesoi / sort.cpp
Created November 26, 2012 23:02
Distributed sort in MPI
/*
* ===========================================================================
*
* Filename: sort.cpp
* Author: Dodon Victor, dodonvictor AT gmail DOT com
* Created: 11/22/2012 04:32:15 PM
* Editor: Vim 7.3
* Compiler: clang 3.2
* OS: Archlinux x86_64
*