Skip to content

Instantly share code, notes, and snippets.

View smspillaz's full-sized avatar
💥
mindblown

Sam Spilsbury smspillaz

💥
mindblown
View GitHub Profile
# From A to Server Rendering, 2018 edition
-- How do I do this again?
Another year, another React app to add server-side rendering support to. For the
uninitiated, Server-Side-Rendering in the context of React is the term used to
describe the use of React itself to do the first render pass of a web-app on the
server and send that to the browser just before it gets the (rather large) JavaScript
bundle for your React App. The browser can display the server-rendered page immediately and then continue running your App once it is done with the bundle.
Server rendering really is one of those things where its great in theory,
/* Copyright 2018 Your name
*
* {{project}} is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* {{project}} is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@smspillaz
smspillaz / matapp.cpp
Created August 19, 2018 15:06
These two should be equivalent....
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),
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 / foo.py
Created October 1, 2018 15:35
Opening files the right way
# 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
@smspillaz
smspillaz / random.py
Created October 31, 2018 17:42
Random Search in Pyton
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)
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))
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))
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))
import fs from 'fs';
function oldStyleAsynchronousFunction(callback) {
fs.readFile('somefile.txt', 'utf8', function(err, result) {
if (err) {
callback(err, null);
return;
}
callback(result);