Skip to content

Instantly share code, notes, and snippets.

@phg1024
phg1024 / threadexample.cpp
Last active November 9, 2023 08:06
a simple thread example to show thread-safe vector operation
#include <iostream>
#include <concurrent_vector.h>
#include <thread>
#include <algorithm>
#include <cstdlib>
#include <atomic>
#include <vector>
#include <mutex>
int counter = 0;
#include <iostream>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <time.h>
#include "vectorclass/vectorf128.h"
#include "alignedallocator.hpp"
install_name_tool -change $oldlib $newlib $programname
// hit point
float eta = 1.01;
ray.origin = h.p;
// entering or leaving
if( dot(ray.dir, h.n) < 0 )
// entering ray
ray.dir = refract(ray.dir, h.n, 1.0/eta);
else
// leaving ray
ray.dir = refract(ray.dir, -h.n, eta);
@phg1024
phg1024 / jfa.m
Last active August 29, 2015 13:56
Jump Flooding Algorithm for generating voronoi diagram
function B = jfa(n, w, h, nsamples)
sites = round([rand(n, 1)*(w-1)+1, rand(n,1)*(h-1)+1]);
rawsites = sites;
if nargin < 4
nsamples = 16;
end
offsets=zeros(nsamples, 2);
sqrtNSamples = round(sqrt(nsamples));
@phg1024
phg1024 / lic.m
Created February 25, 2014 22:17
Line Integral Convolution
function licimg = lic(field)
[height, width, ~] = size(field);
noise = rand(height, width);
% lic length
L = 20.0;
licimg = zeros(height, width);
@phg1024
phg1024 / twitter.py
Created April 23, 2014 00:55
python twitter api test
import twitter
# == OAuth Authentication ==
#
# This mode of authentication is the new preferred way
# of authenticating with Twitter.
# The consumer keys can be found on your application's Details
# page located at https://dev.twitter.com/apps (under "OAuth settings")
C_K="..."
@phg1024
phg1024 / testSampling.m
Created May 8, 2014 03:45
Test cosine weighted sampling and stratified sampling
function testSampling(n)
samples = zeros(n, 3);
samples2 = zeros(n, 3);
for i=1:n
xi1 = rand();
xi2 = rand();
samples(i, :) = hemi(xi1, xi2);
samples2(i, :) = hemi_stratified(xi1, xi2);
@phg1024
phg1024 / findwords.cpp
Created June 23, 2014 02:22
Find all possible words given a matrix of characters.
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
using namespace std;
struct Node {
@phg1024
phg1024 / zigzag.cpp
Created June 28, 2014 23:42
Given an array, convert it to a zigzag pattern.
#include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;
vector<int> solve(vector<int>& A) {
int n = A.size();
int a, b, c;