Skip to content

Instantly share code, notes, and snippets.

View Denommus's full-sized avatar

Yuri Albuquerque Denommus

  • Brick Abode
  • Florianópolis, SC, Brazil
View GitHub Profile
@Denommus
Denommus / headsortails.rb
Created April 28, 2012 03:51
Heads or tails
# Shows all the possibilities of a set of coins throwing
# You could as well change "heads" and "tails" for true and false.
def possibilities(a)
results = []
if(a==1)
results << ["heads"]
results << ["tails"]
else
@Denommus
Denommus / Gemfile
Created April 28, 2012 04:11
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
@Denommus
Denommus / reverse_polish_calc.rb
Last active October 7, 2015 15:57
A calculator using reverse polish notation, written in Ruby
#!/usr/bin/env ruby
arr = []
$stdin.each_line do |n|
n.chop!
break if %w(exit quit).include?(n)
arr << (/[[:digit:]]+/ === n ? n.to_f : n.to_sym)
if arr.last.is_a?(Symbol)
if arr.length < 3
puts 'Not enough numbers in stack.'
@Denommus
Denommus / thumbnail_creator.rb
Created July 31, 2012 01:44
Checks all JPEG's in a given folder and creates thumbnails for them
#!/usr/bin/env ruby
require 'RMagick'
include Magick
dir = ARGV[0].dup
dir << '/' unless dir.match(/\/$/)
thumbnails = Dir.pwd+"/"+dir+"thumbnails"
Dir.chdir(Dir.pwd+"/"+dir)
puts Dir.pwd
puts thumbnails
@Denommus
Denommus / gist:4121339
Created November 20, 2012 21:36
Everything you can override in a refinerycms project with refinerycms-blog
When starting a project that includes refinerycms-blog:
$ rake refinery:override view=refinery/pages/*
$ rake refinery:override view=layouts/*
$ rake refinery:override view=refinery/blog/shared/*
$ rake refinery:override view=refinery/blog/posts/*
$ rake refinery:override view=refinery/*
$ rake refinery:override controller=refinery/blog/*
$ rake refinery:override controller=refinery/*
@Denommus
Denommus / closure-sample.js
Created March 17, 2013 02:05
Example of closure in Javascript
function testeClosure(x) {
return umaLista.filter(
function(y) { return x == y; }
);
}
@Denommus
Denommus / closure-sample.rb
Created March 17, 2013 02:12
An example of a Closure in Ruby, using code block
x = 5
[1, 2, 3, 4].map { |y| y + x } # returns [6, 7, 8, 9]
@Denommus
Denommus / practical-closure.rb
Created March 17, 2013 02:19
A more practical example what a closure could do if well used.
x = 0
[4, 2, 6, 7].each do |y|
x += y
end
puts x # writes 19 on the screen
@Denommus
Denommus / test-closure.java
Last active December 15, 2015 02:29
Trying to make a closure in Java
import java.util.concurrent.atomic.AtomicReference;
public abstract class TestClosure {
public abstract int execute(int a);
}
public class MainClass {
public static void main(String[] args) {
final AtomicReference<Integer> x = new AtomicReference<Integer>(4);
TestClosure testClosure = new TestClosure() {
@Denommus
Denommus / byte-array-to-fixnum-array.lisp
Last active December 15, 2015 09:49
Converts a byte array to a 32-bits unsigned int array
(defun byte-array-to-ui-32-bit-array (octet-array)
(declare (optimize (speed 3))
(type (simple-array (unsigned-byte 8) (*)) octet-array))
(if (/= (mod (length octet-array) 4) 0)
(make-array 0 :element-type '(unsigned-byte 32))
(make-array (/ (length octet-array) 4)
:element-type '(unsigned-byte 32)
:initial-contents
(loop for i from 0 below (length octet-array) by 4
for j = 0 then (1+ j)