Skip to content

Instantly share code, notes, and snippets.

View werediver's full-sized avatar
💭
🦀

Raman Fedaseyeu werediver

💭
🦀
View GitHub Profile
//-->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 / 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
@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 / 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 / validate_py3.py
Created November 5, 2012 09:41
10gen M101 course week 2 homework 2.3 validation script ported to python3
import base64
code="aW1wb3J0IHB5bW9uZ28KaW1wb3J0IHVybGxpYi5yZXF1ZXN0LCB1cmxsaWIuZXJyb3IsIHVybGxpYi5wYXJzZQppbXBvcnQgaHR0cC5jb29raWVqYXIKaW1wb3J0IHJhbmRvbQppbXBvcnQgcmUKaW1wb3J0IHN0cmluZwoKIyBtYWtlcyBhIGxpdHRsZSBzYWx0CmRlZiBtYWtlX3NhbHQobik6CiAgICBzYWx0ID0gIiIKICAgIGZvciBpIGluIHJhbmdlKG4pOgogICAgICAgIHNhbHQgPSBzYWx0ICsgcmFuZG9tLmNob2ljZShzdHJpbmcuYXNjaWlfbGV0dGVycykKICAgIHJldHVybiBzYWx0CgoKIyB0aGlzIGlzIGEgdmFsaWRhdGlvbiBwcm9ncmFtIHRvIG1ha2Ugc3VyZSB0aGF0IHRoZSBibG9nIHdvcmtzIGNvcnJlY3RseS4KCmRlZiBjcmVhdGVfdXNlcih1c2VybmFtZSwgcGFzc3dvcmQpOgogICAgdHJ5OgogICAgICAgIHByaW50KCJUcnlpbmcgdG8gY3JlYXRlIGEgdGVzdCB1c2VyICIsIHVzZXJuYW1lKQogICAgICAgIGNqID0gaHR0cC5jb29raWVqYXIuQ29va2llSmFyKCkKICAgICAgICB1cmwgPSAiaHR0cDovL2xvY2FsaG9zdDo4MDgyL3NpZ251cCIKCiAgICAgICAgZGF0YSA9IHVybGxpYi5wYXJzZS51cmxlbmNvZGUoWygiZW1haWwiLCIiKSwoInVzZXJuYW1lIix1c2VybmFtZSksICgicGFzc3dvcmQiLHBhc3N3b3JkKSwgKCJ2ZXJpZnkiLHBhc3N3b3JkKV0pCiAgICAgICAgcmVxdWVzdCA9IHVybGxpYi5yZXF1ZXN0LlJlcXVlc3QodXJsPXVybCwgZGF0YT1kYXRhLmVuY29kZSgidXRmOCIpKQogICAgICAgIG9wZW5
@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 / SimpleDataSource.swift
Created January 23, 2016 11:44
Pretty universal UITableView / UICollectionView data source implementation in Swift.
import UIKit
class BaseSimpleDataSource<Cell: ReusableView, Collection: CollectionType
where Collection.Index == Int,
Collection.Generator.Element: CollectionType,
Collection.Generator.Element.Index == Int,
Collection.Generator.Element.Generator.Element == Cell.Model>: NSObject {
typealias Item = Cell.Model
import UIKit
import PureLayout
extension UINib {
func instantiateWithOwner<T: AnyObject>(owner: AnyObject?, options: [NSObject : AnyObject]? = nil, type: T.Type) -> T {
let objs = self.instantiateWithOwner(owner, options: options)
return objs.findFirst { $0 is T } as! T
}
@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 / 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