Skip to content

Instantly share code, notes, and snippets.

View kesha-antonov's full-sized avatar
🏆
Working on great apps

Kesha Antonov kesha-antonov

🏆
Working on great apps
View GitHub Profile
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=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')
@kares
kares / simpleFormat.js
Created December 14, 2010 08:56
simple_format Ruby on Rails helper in javascript
var simpleFormatRE1 = /\r\n?/g;
var simpleFormatRE2 = /\n\n+/g;
var simpleFormatRE3 = /([^\n]\n)(?=[^\n])/g;
function simpleFormat(str) {
var fstr = str;
fstr = fstr.replace(simpleFormatRE1, "\n") // \r\n and \r -> \n
fstr = fstr.replace(simpleFormatRE2, "</p>\n\n<p>") // 2+ newline -> paragraph
fstr = fstr.replace(simpleFormatRE3, "$1<br/>") // 1 newline -> br
fstr = "<p>" + fstr + "</p>";
return fstr;
@thbar
thbar / freeze.rake
Created November 27, 2011 11:03
A quick and crappy script to extract gems versions from Gemfile.lock, back into Gemfile
# utterly crappy proof-of-concept that works. for me. today.
task :freeze do
require 'bundler_auto_update'
include Bundler::AutoUpdate
locked_gems = IO.read('Gemfile.lock').match(/^GEM.*^PLATFORMS$/m).to_s.split("\n").grep(/^\s{4}\w/).map(&:strip)
locked_gems = locked_gems.inject({}) { |result, gem| result.merge!(Hash[[gem.gsub(/\(|\)/, '').split]]); result}
gemfile = Gemfile.new
gemfile.gems.each do |g|
@sidane
sidane / capybara_selenium_resize_window.rb
Last active June 3, 2022 13:27
Resize browser window with Capybara Selenium
# Resize selenium browser window to avoid Selenium::WebDriver::Error::MoveTargetOutOfBoundsError errors
#
# Example usage with Rspec (in spec/support/spec_helper.rb):
#
# config.before(:each) do
# set_selenium_window_size(1250, 800) if Capybara.current_driver == :selenium
# end
#
def set_selenium_window_size(width, height)
window = Capybara.current_session.current_window.resize_to
@kinopyo
kinopyo / gist:2224867
Created March 28, 2012 08:52
Check whether a Paperclip attachment exists

Check whether a Paperclip attachment exists

Don’t simply test for the presence of the magic Paperclip attribute, it will return a paperclip Attachment object and thus always be true:

- if user.photo.present? # always true
  = image_tag(user.photo.url)
@mklnz
mklnz / capistrano_sudo_helpers.rb
Created April 17, 2012 18:12
Sudo put and template methods for Capistrano
# I got tired of uploading to /tmp then moving to the correct location, so these two convenience methods will save you a lot of time in the long run.
# Helper method to upload to /tmp then use sudo to move to correct location.
def put_sudo(data, to)
filename = File.basename(to)
to_directory = File.dirname(to)
put data, "/tmp/#{filename}"
run "#{sudo} mv /tmp/#{filename} #{to_directory}"
end
@jonathanmoore
jonathanmoore / gist:2640302
Created May 8, 2012 23:17
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@ludder
ludder / slideDown.js
Created December 6, 2012 17:25
Vanilla JavaScript slideUp and slideDown functions
/*
Element to slide gets the following CSS:
max-height: 0;
opacity: 0;
overflow: hidden;
transition: max-height 0.4s ease 0s;
*/
/**
* Like jQuery's slideDown function - uses CSS3 transitions
@maxivak
maxivak / send_data-send_file-remote-images-download
Created January 1, 2013 23:34
Rails. Download remote image as attachment in browser
# in controller
# for local files
send_file '/path/to/file', :type => 'image/jpeg', :disposition => 'attachment'
# for remote files
require 'open-uri'
url = 'http://someserver.com/path/../filename.jpg'
data = open(url).read
send_data data, :disposition => 'attachment', :filename=>"photo.jpg"
@alex-zige
alex-zige / gist:5795358
Last active June 8, 2023 07:49
Rails Rspec API Testing Notes

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views