Skip to content

Instantly share code, notes, and snippets.

@simplay
simplay / Ruby_Lambda_Fun_Numerical _Integration_Trapezoid.rb
Last active April 22, 2022 15:23
# Numerical Integraion over real domain of real 1d valued functions using Newton-Cotes approximation. # NB1: Error of approximation in O(f'' * (b-a)^3 ) # NB2: In practice quite usable for many common functions, like affine, trigonomatric function
# D subset |R Domain over which we integrate - sample D = [1,10]
D = (1..10).to_a
# f:|R->|R function - sample x |-> f(x) := x^2
f = lambda {|x| x*x}
# summation of function values over our domain
summator = lambda {|function, domain| domain.inject(0){|x,y| x += function.call(y)} }
# Integrations Driver (for real valued 1d functions only) - assumption: integration steps equidistant
@simplay
simplay / refactoring_using_metaprogrammin.rb
Created May 20, 2013 14:57
Refactoring in Ruby using dynamic methods and dynamic dispatch (1) using dynamic proxy that is also a blank slate (2) source: book - metaprogramming-ruby
# given class Computer: refactor me
class Computer
def initialize(computer_id, data_source)
@id = computer_id
@data_source = data_source
end
def mouse
info = @data_source.get_mouse_info(@id)
price = @data_source.get_mouse_price(@id)
@simplay
simplay / own_dsl.rb
Created May 21, 2013 18:30
event monitoring system - example for scope, blocks, procs, lambdas in ruby source: metaprogramming-ruby
lambda {
setups = []
events = {}
Kernel.send :define_method, :event do |name, &block|
events[name] = block
end
Kernel.send :define_method, :setup do |&block|
setups << block
end
@simplay
simplay / gist:9642897
Last active August 29, 2015 13:57
Github markdown cheatsheet
Checkboxes
- [x] A
- [x] B
- [x] C
~~Durchgestrichen~~
FooImage
![NAME](adresse/file.format)
@simplay
simplay / closure_example.js
Last active August 29, 2015 14:01
Example how to define a javascript class
// a sample class decleration showing javascript closure examples.
// Keep in mind: prototyped properties affect all objects of the
// same constructor, simultaneously, even if they already exist.
function Knight(hp){
// public attribute of Knight
this.hp = hp;
// private attribute of Knight
var secreteHP = hp+1;
@simplay
simplay / hof
Last active August 29, 2015 14:05
Higher order function examples.rb
# map two lists: e.g sum elementwise
[1,2,3].zip([4,5,6]).map{|a,b| a+b}
# reset local master
git fetch origin
git reset --hard origin/master
# show code diff of a COMMIT
git show COMMIT
# rabse last NUMBEROFCOMMITS commits (including head)
git rebase -i HEAD~NUMBEROFCOMMITS
@simplay
simplay / gist:981e7bf717baf0089712
Last active August 29, 2015 14:07
Fun Project Ideas
Ruby
Game of Life in Ruby - my old omnipresent friend <3
Collection of Sorting algorithms
Own DSL arrogating Matlab
SVM for higherdimensional classifiers
A general Ruby Convas (imagine it would directly make use of OpenGL...)
@simplay
simplay / Matlab cheatsheet
Created October 7, 2014 13:42
Matlab cheat-sheet
% gives a gaussain kernel of size (dim_n x dim_x) having a variance equal to sigma_value.
fspecial('gaussian', dim_n, sigma_value)
@simplay
simplay / brightnessCenter.m
Last active August 29, 2015 14:07
Brigthness center in image using a brightness threshold using image masking
% example determining brightness center from a given image A
% Args to provide: mask, image, threshold (perhaps).
% given a selection mask and image A like the following:
mask =
1 0 0 0
1 1 0 0
1 1 0 0
0 1 1 1