Skip to content

Instantly share code, notes, and snippets.

@valikos
valikos / products.rb
Last active January 4, 2016 22:19
Crazy counter
# before
# solution from member of team
if hash["#{PRODUCT_TYPEID_VDC}"].nil? && hash["#{PRODUCT_TYPEID_PRIVATECLOUD}"].nil?
hash["#{PRODUCT_TYPEID_VDC}"] = hash["#{PRODUCT_TYPEID_CLOUD}"]
elsif hash["#{PRODUCT_TYPEID_VDC}"].nil? && hash["#{PRODUCT_TYPEID_CLOUD}"].nil?
hash["#{PRODUCT_TYPEID_VDC}"] = hash["#{PRODUCT_TYPEID_PRIVATECLOUD}"]
elsif hash["#{PRODUCT_TYPEID_CLOUD}"].nil?
hash["#{PRODUCT_TYPEID_VDC}"] += hash["#{PRODUCT_TYPEID_PRIVATECLOUD}"] unless hash["#{PRODUCT_TYPEID_PRIVATECLOUD}"].nil?
elsif hash["#{PRODUCT_TYPEID_PRIVATECLOUD}"].nil?
hash["#{PRODUCT_TYPEID_VDC}"] += hash["#{PRODUCT_TYPEID_CLOUD}"] unless hash["#{PRODUCT_TYPEID_CLOUD}"].nil?
@valikos
valikos / time_to_live.rb
Last active August 29, 2015 14:08
Class implements 'time to live' functionality
require 'singleton'
require 'active_support'
class TimeToLive
include Singleton
attr_reader :start_time
def initialize
@live = true
# research about this
Marshal.load(Marshal.dump(variable))
@valikos
valikos / psql
Created January 26, 2015 10:05
How to create new user in postgres with password and interactive mode
# create user
createuser --interactive -P role_name
# remove user
dropuser role_name
@valikos
valikos / eval-ssh
Created January 31, 2015 11:33
Eval ssh
# start the ssh-agent in the background
eval "$(ssh-agent -s)"
# Agent pid 59566
ssh-add ~/.ssh/id_rsa
@valikos
valikos / file-mode.txt
Created April 10, 2015 07:36
File access mode description
Mode | Meaning
-----+--------------------------------------------------------
"r" | Read-only, starts at beginning of file (default mode).
-----+--------------------------------------------------------
"r+" | Read-write, starts at beginning of file.
-----+--------------------------------------------------------
"w" | Write-only, truncates existing file
| to zero length or creates a new file for writing.
-----+--------------------------------------------------------
"w+" | Read-write, truncates existing file to zero length
@valikos
valikos / docker-stop-remove
Created April 10, 2015 10:01
docker stop and remove oneline commands
One liner to stop / remove all of Docker containers:
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
@valikos
valikos / vector.js
Last active August 29, 2015 14:19
Practice task from "Eloquent Javascript"
var Vector = function(x, y) {
this.x = x;
this.y = y;
}
Vector.prototype.plus = function(vector) {
return new Vector.new(this.x + vector.x, this.y + vector.y)
}
Vector.prototype.minus = function(vector) {
@valikos
valikos / rbenv_install
Created July 15, 2015 21:05
How to install old ruby versions on OSX
> brew install gcc48
> CC=gcc-4.8 rbenv install 1.8.7-p375
@valikos
valikos / variable.rb
Created July 21, 2015 08:07
Variables in ruby
class A
@foo = :foo
@@bar = :bar
attr_reader :foo
def foo
@foo = :bla
end