Skip to content

Instantly share code, notes, and snippets.

View cassioscabral's full-sized avatar

Cassio Cabral cassioscabral

View GitHub Profile
@cassioscabral
cassioscabral / array_iteration_thoughts.md
Created January 13, 2017 00:40 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@cassioscabral
cassioscabral / putonglasses.txt
Created July 20, 2016 13:23 — forked from cheeaun/putonglasses.txt
put on glasses unicode
•_•)
( •_•)>⌐■-■
(⌐■_■)
@cassioscabral
cassioscabral / new_tab.AppleScript
Created January 8, 2016 16:14
New tab on applescript code
on new_tab()
tell application "Terminal"
activate
tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
end tell
end new_tab
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@cassioscabral
cassioscabral / gist:fe40942b328d12701592
Created February 5, 2015 17:03
Capybara measure time stress test
it "should access the page 20 times" do
beginning_time_all = Time.now
(1..20).each do |i|
beginning_time = Time.now
visit "/my/page"
end_time = Time.now
puts "Time elapsed #{(end_time - beginning_time)*1000} milliseconds"
end
end_time_all = Time.now
puts "ALL -> Time elapsed #{(end_time_all - beginning_time_all)*1000} milliseconds"
@cassioscabral
cassioscabral / posts_list.rb
Created January 14, 2015 13:25
Getting all posts limited
@all_posts = []
@categories = Category.includes(:posts)
@categories.each do |category|
@all_posts.concat(category.posts.limit(3))
end
# precisando acessar uma category de um post == post.category
@all_posts.each do |post|
post.category
@cassioscabral
cassioscabral / programming_languages.css
Created January 11, 2015 05:38
Github programming languages colors in Hex
.ags-script-color {
background: #B9D9FF;
}
.antlr-color {
background: #9DC3FF;
}
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)