Skip to content

Instantly share code, notes, and snippets.

View werediver's full-sized avatar
💭
🦀

Raman Fedaseyeu werediver

💭
🦀
View GitHub Profile
@werediver
werediver / BasicServiceLocator.swift
Last active January 14, 2019 06:13
Basic Service Locator pattern implementation in Swift 2.
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 {
@werediver
werediver / xcorr.py
Created September 29, 2014 14:00
Sample code
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()
@werediver
werediver / xcorr-mess.py
Last active May 1, 2016 13:23
Demonstration of different approaches to calculating cross-correlation (code written in IPython Notebook).
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))
@werediver
werediver / CircularQueue.h
Created August 22, 2014 11:45
Simple implementation of circular queue in Objective-C (for ARC-enabled environment).
//
// CircularQueue.h
//
// Created on 9/21/13.
//
#import <Foundation/Foundation.h>
@interface CircularQueue : NSObject <NSFastEnumeration>
@werediver
werediver / ssa-octave.m
Last active May 5, 2016 14:17
ssa.sci ( https://gist.github.com/werediver/9785544 ) adapted for GNU Octave
% 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
@werediver
werediver / ssa.sci
Last active August 29, 2015 13:57
Basic SSA (Singular Spectrum Analysis) implementation for Scilab.
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)
@werediver
werediver / adiag.sci
Created March 12, 2014 13:09
Scilab function returning 2D matrix antidiagonal by index.
//-->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
//-->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
@werediver
werediver / wing_ar.hs
Created July 5, 2013 11:44
Wing aspect ratio calculator in Haskell.
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
@werediver
werediver / singleton.py
Created December 28, 2012 09:51
A thread safe implementation of singleton pattern in Python. Based on tornado.ioloop.IOLoop.instance() approach.
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