Skip to content

Instantly share code, notes, and snippets.

Avatar
💥
mindblown

Sam Spilsbury smspillaz

💥
mindblown
View GitHub Profile
View gist:f2049694eb847604e36cd6ffc218086f
void inplace_merge(int *first, int *mid, int *end) {
int *datacopy[size of data];
int *left = first;
int *right = end;
int next = 0;
int n = end - first;
while (next < n) {
if (left < mid && *left < *right) {
datacopy[next++] = *left;
} else if (right < end) {
View gist:72ff76e053e35506aa500fca72e8e6f1
for (int size = 1; size < n; size = 2 * size) {
int nSegments = n / size;
#pragma omp for
for(int segment = 0; segment < nSegments; ++segment) {
int leftStart = segment * size;
int mid = min(leftStart + (size / 2), n-1);
int rightEnd = min(leftStart + size, n-1);
merge(data, leftStart, mid, rightEnd);
}
View await-promises.js
import fs from 'fs';
function oldStyleAsynchronousFunction(callback) {
fs.readFile('somefile.txt', 'utf8', function(err, result) {
if (err) {
callback(err, null);
return;
}
callback(result);
View pareto_optimization.py
def both_objectives(layout, columns, *args):
return (frequency_objective(layout,*args),
similarity_objective(layout,*args))
def random_evaluated_design(seed_design, objective_function, *args):
"""Return a new random design, evaluated by objective_function"""
candidate = random.sample(seed_design, len(seed_design))
return (candidate, *objective_function(candidate, *args))
View pareto_optimization.py
def both_objectives(layout, columns, *args):
return (frequency_objective(layout,*args),
similarity_objective(layout,*args))
def random_evaluated_design(seed_design, objective_function, *args):
"""Return a new random design, evaluated by objective_function"""
candidate = random.sample(seed_design, len(seed_design))
return (candidate, *objective_function(candidate, *args))
View pareto_optimization
def both_objectives(layout, columns, *args):
return (frequency_objective(layout,*args),
similarity_objective(layout,*args))
def random_evaluated_design(seed_design, objective_function, *args):
"""Return a new random design, evaluated by objective_function"""
candidate = random.sample(seed_design, len(seed_design))
return (candidate, *objective_function(candidate, *args))
@smspillaz
smspillaz / random.py
Created Oct 31, 2018
Random Search in Pyton
View random.py
import random
def random_search(array, iterations, objective, *args):
"""Do a random search over the array for :iterations:."""
best = array[0]
best_value = objective(best, *args)
for i in range(iterations):
candidate = random.sample(best, len(best))
value = objective(candidate, *args)
@smspillaz
smspillaz / foo.py
Created Oct 1, 2018
Opening files the right way
View foo.py
# So generally speaking, if you want to be opening files with Python
# its better to observe the "Easier to ask for forgiveness than permission"
# principle (EAFP) where just blindly try to open the file as though it
# existed and then handle exceptions where it does not:
#
# The reason why you should do this is two fold:
# (1) Checking first always imposes a performance cost due
# to the extra system call overhead.
# (1.1) Unlike languages like C++, you always pay the
# cost of exception paths in Python, so it makes
View gist:f8a92421321653a3a86d79bce0899462
M /metadata
M /files/manifest.json
M /files/lib/libcontentfeed-0.so.0.0.0
M /files/lib/libeknr-0.so.0.0.0
M /files/lib/libendless-0.so.0.500.0
M /files/lib/libeoscompanion-1.so.0.0.0
M /files/lib/python3.5/site-packages/eoscompanion/__pycache__/__init__.cpython-35.opt-1.pyc
M /files/lib/python3.5/site-packages/eoscompanion/__pycache__/applications_query.cpython-35.opt-1.pyc
M /files/lib/python3.5/site-packages/eoscompanion/__pycache__/constants.cpython-35.opt-1.pyc
M /files/lib/python3.5/site-packages/eoscompanion/__pycache__/content_streaming.cpython-35.opt-1.pyc
@smspillaz
smspillaz / matapp.cpp
Created Aug 19, 2018
These two should be equivalent....
View matapp.cpp
auto translationMat = glm::translate (
glm::mat4 (1.0),
glm::vec3 (agd::get <0> (translation),
agd::get <1> (translation),
0.0)
);
auto invCenterMat = glm::translate (
glm::mat4 (1.0),
glm::vec3 (-1 * agd::get <0> (intendedCenter),
-1 * agd::get <1> (intendedCenter),