Skip to content

Instantly share code, notes, and snippets.

View kstratis's full-sized avatar

Konstantinos Stratis kstratis

  • ▅▆▇
  • Athens, Greece
View GitHub Profile
@sj26
sj26 / array-pluck.rb
Created December 9, 2011 03:05
Gather values from an array of hashes
class Array
def pluck key
map { |hash| hash[key] }
end
end
[{:number => "1"}, {:number => "2"}, {:number => "3"}].pluck(:number)
# => ["1", "2", "3"]
@jaysonrowe
jaysonrowe / FizzBuzz.py
Created January 11, 2012 03:05
FizzBuzz Python Solution
def fizzbuzz(n):
if n % 3 == 0 and n % 5 == 0:
return 'FizzBuzz'
elif n % 3 == 0:
return 'Fizz'
elif n % 5 == 0:
return 'Buzz'
else:
return str(n)
@mklickman
mklickman / _form.html.erb
Created February 10, 2012 17:01
Basic Rails Contact Form and Mailer
<%= form_for(@contact) do |f| %>
<% if @contact.errors.any? %>
<div id="error_explanation">
<h3><%= pluralize(@contact.errors.count, "error") %> prohibited this contact from being saved:</h2>
<ul>
<% @contact.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
@chetan
chetan / yardoc_cheatsheet.md
Last active April 13, 2025 14:08
YARD cheatsheet
@andrewwatts
andrewwatts / request_time.py
Created March 10, 2012 19:33
urllib2 vs urllib3 vs requests
#!/usr/bin/env python2.7
import time
_URL = 'http://localhost/tmp/derp.html'
_NUMBER = 1000
def test_urllib2():
import urllib2
@IanVaughan
IanVaughan / uninstall_gems.sh
Created June 9, 2012 20:37
Uninstall all rbenv gems
#!/usr/bin/env bash
uninstall() {
list=`gem list --no-versions`
for gem in $list; do
gem uninstall $gem -aIx
done
gem list
gem install bundler
}
@pwightman
pwightman / httparty.md
Created November 8, 2012 02:38
HTTParty usage

This is a much simpler HTTP library called HTTParty. The standard library that comes with Ruby is quite verbose, you have to convert a string to a URL, specify URLs and ports and all sorts of longwinded stuff. This is much easier. There's both a command line interface, if you just want to test things out for the queue at the command line, for example, as well as a ruby library. I'll show both here. You can install it with gem install httparty.

Command-line usage:

httparty -H Accept:application/json "http://nine.eng.utah.edu/schools"

# Accepts JSON, uses POST instead of GET, and does BASIC authentcation, which the queue requires
# once you've logged in. I can show you that later.
httparty -H Accept:application/json -a post -u username:password "http://nine.eng.utah.edu/schools"
@ctalkington
ctalkington / Gemfile
Last active October 26, 2024 04:10
Nginx, Sinatra, and Puma.
source :rubygems
gem "puma"
gem "sinatra"
@tomas-stefano
tomas-stefano / Capybara.md
Last active May 14, 2025 18:17
Capybara cheatsheet

Capybara Actions

# Anchor
click_link 'Save'

# Button
click_button 'awesome'

# Both above
@ajtroxell
ajtroxell / contact.html
Last active February 10, 2025 17:29
Build a simple PHP, jQuery, and AJAX Powered Contact Form, from: http://ajtroxell.com/build-a-simple-php-jquery-and-ajax-powered-contact-form/
<form id="contact" name="contact" method="post">
<fieldset>
<label for="name" id="name">Name<span class="required">*</span></label>
<input type="text" name="name" id="name" size="30" value="" required/>
<label for="email" id="email">Email<span class="required">*</span></label>
<input type="text" name="email" id="email" size="30" value="" required/>
<label for="phone" id="phone">Phone</label>
<input type="text" name="phone" id="phone" size="30" value="" />