Skip to content

Instantly share code, notes, and snippets.

@mzdravkov
mzdravkov / Example iterator test
Created May 9, 2013 12:06
Example code for testing the String::iterator from OOP homework.
String str1("Llama");
cout << "str1: " << str1[0] << str1[1] << str1[2] << str1[3] << str1[4] << str1[5] << endl;
cout << "*str1.begin(): " << *str1.begin() << endl;
cout << "*str1.end() == /0: " << (*str1.end() == '\0') << endl;
cout << "*++++++++++str1.begin() == /0: " << (*++++++++++str1.begin() == '\0') << endl;
cout << "++++++++++str1.begin() != str1.end(): " << ((++++++++++str1.begin()) != str1.end()) << endl;
for (String::iterator i = str1.begin(); i != str1.end(); i++) {
@mzdravkov
mzdravkov / Test string.
Created May 11, 2013 20:55
Test OOP homework 1. (String)
String str1("Llama");
cout << "str1: " << str1[0] << str1[1] << str1[2] << str1[3] << str1[4] << str1[5] << endl;
cout << "*str1.begin(): " << *str1.begin() << endl;
cout << "*str1.end() == /0: " << (*str1.end() == '\0') << endl;
cout << "*++++++++++str1.begin() == /0: " << (*++++++++++str1.begin() == '\0') << endl;
cout << "++++++++++str1.begin() != str1.end(): " << ((++++++++++str1.begin()) != str1.end()) << endl;
for (String::iterator i = str1.begin(); i != str1.end(); i++) {
@mzdravkov
mzdravkov / Task 1
Created May 26, 2013 13:00
Octave tasks from classwork.
p = [1 -3 2];
r = roots(p);
x = linspace(-1, 3);
plot(x, polyval(p, x));
hold on;
plot(r, zeros(size(r)), "marker", "x", "markersize", 21, "color", "red", "linestyle", "none")
hold on;
plot(x, zeros(size(x)), '.', 'color', 'red');
@mzdravkov
mzdravkov / ruby_lazy_eval
Last active December 23, 2015 04:49
Ruby's fibers (lazy eval example)
all_nums = Fiber.new do
num = 0
while true
Fiber.yield num
num += 1
end
end
all_nums.resume # => 0
all_nums.resume # => 1
@mzdravkov
mzdravkov / Ruby apply
Last active December 23, 2015 22:18
Apply method for Ruby's Object, as (maybe?) more clean alternative to long method chain.
Object.class_eval do
def apply(&block)
instance_eval(&block) if block_given?
end
end
arr = []
arr.apply do
push [1, 2]
p self # => [[1, 2]]
@mzdravkov
mzdravkov / .bashrc
Created September 26, 2013 07:55
My .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
shopt -s autocd
export ISE_EIFFEL=~/Downloads/Eiffel73
export ISE_PLATFORM=linux-x86
export PATH=$ISE_EIFFEL/studio/spec/$ISE_PLATFORM/bin:~/.bin/elixir-0.10.2/bin/:~/.bin/:$PATH
@mzdravkov
mzdravkov / .profile
Created September 26, 2013 07:59
My .profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
(defn move-boxes
([[box & cboxes] pos] (move-boxes box cboxes pos))
([box cboxes pos]
(do some things)
(if (> pos 0)
(move-boxes box cboxes (dec pos))
(move-boxes cboxes (dec pos)))))
@mzdravkov
mzdravkov / pathfinder
Last active December 24, 2015 02:19
An attempt (fail) to create ultra simple path finding algorithm in maze in Clojure.
; 'from' is the current point of search, 'to' is the target, level is the maze/2DMatrix
(defn pathar
([level from to] (pathar level from to []))
([level from to path]
(if (= from to)
path
(let [nb (valid-neighbours level from)] ;valid neighbours returns the indexes of all valid (in the 2dmatrix) neighbour elements.
(pmap #(pathar level % to (cons from path)) nb)))))
@mzdravkov
mzdravkov / rails_associations_rocks.rb
Last active December 26, 2015 14:19
Some associations code that doesn't want to work.
class GroupCalendar < Calendar # Calendar inherits ActiveRecord:Base
has_and_belongs_to_many :users
has_many :sub_inheritances
# has_many :sub_calendars, through: :sub_inheritances, as: :calendarable # <- this line should be as the following:
has_many :sub_calendars, through: :sub_inheritances, source: :calendarable, source_type: :Calendar
end
class SubInheritance < ActiveRecord::Base