Skip to content

Instantly share code, notes, and snippets.

View iogakos's full-sized avatar

Ioannis Gakos iogakos

  • London, United Kingdom
View GitHub Profile
/*
* Toggles character case
*
* e.g in: 'b' -> out: 'B'
* in: 'B' -> out: 'b'
* in: '5' -> out: '5'
*
* @param c ascii character to be toggled
* @return toggled ascii character if alphabetical,
* otherwise intact value of c
# ENV
# RUBY_HEAP_MIN_SLOTS=1000000
# RUBY_HEAP_SLOTS_INCREMENT=1000000
# RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
# RUBY_GC_MALLOC_LIMIT=1000000000
# RUBY_HEAP_FREE_MIN=1000000
# str_gsub() using its regular form (regex, replacement)
[:before_string_build, 0]
[:after_string_build, 26420]
GC::Profiler.enable
vm_before = File.read("/proc/#{$$}/status").match(/^VmSize:\s*(\d*)/)[1].to_i
def vm_used(vm_before)
File.read("/proc/#{$$}/status").match(/^VmSize:\s*(\d*)/)[1].to_i - vm_before
end
# w/o block
def gsub_wo(s)
GC::Profiler.enable
vm_before = File.read("/proc/#{$$}/status").match(/^VmSize:\s*(\d*)/)[1].to_i
def vm_used(vm_before)
File.read("/proc/#{$$}/status").match(/^VmSize:\s*(\d*)/)[1].to_i - vm_before
end
# w block
def gsub_w(s)
@iogakos
iogakos / ruby_gc_goes_wild.rb
Last active December 19, 2015 08:39
Strange behavior of Ruby's GC. ## Careful !! The following script requires ~40Mb of your virtual memory address space.
## Careful !!
# The following script requires ~40Mb of your virtual memory address space.
vm_before = File.read("/proc/#{$$}/status").match(/^VmSize:\s*(\d*)/)[1].to_i
def vm_used(vm_before)
File.read("/proc/#{$$}/status").match(/^VmSize:\s*(\d*)/)[1].to_i - vm_before
end
# w block
@iogakos
iogakos / wma_hash.rb
Created November 22, 2012 09:40
Weighted Moving Average - Ruby Implementation
# Weighted Moving Average (WMA)
# http://en.wikipedia.org/wiki/Moving_average#Weighted_moving_average
#
# Given a hash, calculates the weighted moving averages of its values within
# a window size given. Modifies the original hash values.
#
# @param hash [Hash] the hash for whom values calculate the weighted moving
# averages.
# @param maws [Fixnum] the Moving Average Window Size. The greatest this
# number is the smoothest the calculated averages will be.
@iogakos
iogakos / radio.sh
Created September 19, 2012 10:11
Fav radio station load script using VLC
#!/usr/bin/osascript
tell application "VLC"
activate
OpenURL "<stream_url_goes_here>"
play
end tell
@iogakos
iogakos / gist:1700648
Created January 29, 2012 21:06
The AC-3 algorithm, the ruby way
def calculate_worklist(bishops)
worklist = Array.new
bishops.each { |b|
worklist.unshift("#{b[0]}") && next if b[1] != [nil, nil]
worklist << b[0]
}
worklist.combination(2).to_a
end
def pick_position(positions)
%%
% Authors:
% - Ioannis Gakos, 3634
% - Alkis Livathinos, 3690
%%
% Place disk on a pole
%
:- dynamic disk_state/2.