Skip to content

Instantly share code, notes, and snippets.

View oddlyfunctional's full-sized avatar

Marcos Felipe Pimenta Rodrigues oddlyfunctional

View GitHub Profile
@oddlyfunctional
oddlyfunctional / teste.rb
Created April 6, 2017 12:42
Outra coisa
puts "Hello world!"
@oddlyfunctional
oddlyfunctional / teste.rb
Created April 6, 2017 12:42
Alguma coisa
puts "Hello world!"
http.get('/first_resource')
.map(response => response.json())
.flatMap(firstResource => {
if (firstResource.someProperty) {
return http.get(`/first_resource/${firstResource.id}/second_resource`);
} else {
return Observable.never();
}
}).subscribe(handleSecondaryResource);
@oddlyfunctional
oddlyfunctional / find_adjectives.rb
Last active July 27, 2016 23:57
Find adjectives in standard UNIX dictionary of words
words_path = [
'/usr/share/dict/words'
'/usr/dict/words'
].find { |path| File.exists?(path) }
fail "Couldn't find words file in the system" unless words_path
# I’m using each_line so we don’t load everything
# into memory at once, since the file is huge.
awesome_adjectives = File.open(words_path, 'r')

Roadmap for a beginner

Broad definitions of "levels of a programmer":

  • Beginner: still struggles with algorithmic thinking.
  • Elementary: knows how to write an algorithm, but is still learning how to properly structure his code (just want to make things work). Also doesn't fully understand how the technology stack he's using is integrated. In a web application context, he'd struggle with integrating an AJAX request. Follows religiously the framework's guidelines, even when he shouldn't.
  • Intermediate: knows how to build full applications, and is excited about best practices and design patterns. Hates repetition, and is easily convinced of any new "best practice" to the point where he'll over-design an application and make it even more difficult to maintain than if there wasn't any abstraction. Knows how to use the available tools to perform almost any given task, and is starting to escape the framework's guidelines when appropriate.
  • Advanced (I'd be framed at this level, I think): understands when
# Given a user containing a `first_name` and a `last_name` methods, write a `handle`
# method that returns a generated handle that follow the following rules:
# - It must be preceded by an @
# - It must be all lowercase
# - It contains the first letter of the first name, and all the letters of the last
# name (for "John" "Doe", it'd be @jdoe)
# - If the first name contains more than one name, get the first letter of each name
# ("John Fitzgerald Wood" "Doe" becomes @jfwdoe)
# - If the last name contains more than one name, get all the letters of the last one,
# and the first letter of each other ("John" "Fitzgerald Wood Doe" becomes @jfwdoe)
var Stack = function(){
this.storage = "";
this.frameSize = 20;
this.emptySpaceChar = '$';
};
Stack.prototype.paddingRight = function(val) {
for(var i = val.length; i <= this.frameSize; i++) {
val += this.emptySpaceChar;
}
@oddlyfunctional
oddlyfunctional / custom_layout.rb
Created June 9, 2016 05:53
Different ways to apply custom layouts to a controller's actions
# Passing a String to the layout:
class TestsController < ApplicationController
layout "test_layout" # maps to app/views/layout/test_layout.html.[erb/haml/slim/whatever template engine you're using]
# The test_layout is going to be applied here...
def index
end
# ...and here as well
def new
@oddlyfunctional
oddlyfunctional / example.html
Created June 1, 2016 20:34
Show spinner over image while it's loading
<load-image>
<img #loadImage src="http://orig12.deviantart.net/210f/f/2014/146/9/e/snowy_winter_background_by_archangelical_stock-d7jtb1d.jpg"/>
</load-image>
$timeout(function() {
if (!$scope.promiseComplete && $scope.submitted) {
$scope.message = {
content: [{
title: '',
msg: 'Service down - created'
}],
type: 'error'
};