This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ServiceLocator { | |
func getService<T>() -> T? | |
} | |
final class BasicServiceLocator: ServiceLocator { | |
// Service registry | |
private lazy var reg: Dictionary<String, Any> = [:] | |
private func typeName(some: Any) -> String { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division, print_function | |
import numpy as np | |
import matplotlib.pyplot as pp | |
def xcorr(a, b, mode='same'): | |
a = np.asarray(a) | |
b = np.asarray(b) | |
a = a - a.mean() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division, print_function | |
import numpy as np | |
import matplotlib.pyplot as pp | |
%matplotlib inline | |
def xcorr(a, b, mode='same'): | |
a = np.asarray(a) | |
b = np.asarray(b) | |
a = (a - a.mean()) / np.sqrt(np.correlate(a, a)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CircularQueue.h | |
// | |
// Created on 9/21/13. | |
// | |
#import <Foundation/Foundation.h> | |
@interface CircularQueue : NSObject <NSFastEnumeration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Force GNU Octave to interpret this file as a script | |
1; | |
function [y_out, m, sig] = ssa_normalize(y) | |
% http://en.wikipedia.org/wiki/Student%27s_t-statistic | |
m = mean(y); | |
sig = sqrt(variance(y)) % stdev(y); | |
y_out = (y - m) / sig; | |
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [y_out, m, sig] = ssa_normalize(y) | |
// http://en.wikipedia.org/wiki/Student%27s_t-statistic | |
m = mean(y) | |
sig = sqrt(variance(y)) // stdev(y) | |
y_out = (y - m) / sig | |
endfunction | |
function [y_out] = ssa(y, L, I) | |
[LAMBDA, U, V] = ssa_decompose(y, L) | |
y_out = ssa_reconstruct(LAMBDA, U, V, I) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-->adiag([1 2 3 4; 5 6 7 8; 9 10 11 12],3)' | |
// ans = | |
// 9. 6. 3. | |
function [v] = adiag(x, z) | |
// 2D matrix antidiagonal | |
[N, M] = size(x) | |
// The total diagonals count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-->fill(3,5) | |
// ans = | |
// 1. 3. 4. 9. 10. | |
// 2. 5. 8. 11. 14. | |
// 6. 7. 12. 13. 15. | |
function [x] = fill(N, M) | |
x = zeros(N, M) | |
Z = N + M - 1 | |
i = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module WingAR where | |
import Data.Maybe | |
import Text.Printf | |
-- See http://en.wikipedia.org/wiki/Aspect_ratio_%28wing%29 | |
wing_ar :: Float -> Float -> Float | |
wing_ar l s = l^2 / s | |
readMaybe s = listToMaybe $ fmap fst $ reads s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
# Based on tornado.ioloop.IOLoop.instance() approach. | |
# See https://github.com/facebook/tornado | |
class SingletonMixin(object): | |
__singleton_lock = threading.Lock() | |
__singleton_instance = None | |
@classmethod |