Skip to content

Instantly share code, notes, and snippets.

@Siyanda
Siyanda / capybara cheat sheet
Created August 15, 2022 19:17 — forked from zhengjia/capybara cheat sheet
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')
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML:Document for the page we're interested in...
doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
# Do funky things with it using Nokogiri::XML::Node methods...
####
require 'mechanize'
require 'moving_average'
mechanize = Mechanize.new
login_page = mechanize.get 'https://www.myfitnesspal.com/account/login'
form = login_page.forms.first
# noinspection RubyResolve
form.field_with(id: 'username').value = "username"
form.field_with(id: 'password').value = "pass"
form.submit
@Siyanda
Siyanda / _mixins.scss
Created July 11, 2016 11:42 — forked from garyharan/_mixins.scss
Useful scss mixins (rounded corners, gradients, text-field, button)
@mixin box-shadow($top, $left, $blur, $color, $inset: false) {
@if $inset {
-webkit-box-shadow:inset $top $left $blur $color;
-moz-box-shadow:inset $top $left $blur $color;
box-shadow:inset $top $left $blur $color;
} @else {
-webkit-box-shadow: $top $left $blur $color;
-moz-box-shadow: $top $left $blur $color;
box-shadow: $top $left $blur $color;
}
@Siyanda
Siyanda / Detach.js
Created April 23, 2016 18:20
jQuery – detach elements to work with them
// http://upshots.org/javascript/jquery-detach-elements-to-work-with-them
$.fn.insertAt = function(elements, index) {
var array = $.makeArray(this.children().clone(true));
array.splice(index, 0, elements);
this.empty().append(array);
return this;
};
$.fn.work = function(callback /*, ... rest */){
var params = Array.apply(null, arguments).slice(1);
var parent = this.parent();
// adds class "foo" to el
el.classList.add("foo");
// removes class "bar" from el
el.classList.remove("bar");
// toggles the class "foo"
el.classList.toggle("foo");
// outputs "true" to console if el contains "foo", "false" if not
@Siyanda
Siyanda / CodePen-tut.jade
Created August 18, 2015 21:03
Some helpful Jade syntax stuffs
// Loops (for) (each)
ul
for animal in ['dog', 'cat', 'mouse']
li= animal
// will render unordered list of items mentioned in animal arry
ul
each animal, index in ['dog', 'cat', 'mouse']
li #{index + 1}. #{animal}
@Siyanda
Siyanda / wordpress
Created January 18, 2015 21:01
css-tricks snipets
// detect and embed gists
<?php
// [gist id="ID" file="FILE"]
function gist_shortcode($atts) {
return sprintf(
'<script src="https://gist.github.com/%s.js%s"></script>',
$atts['id'],
$atts['file'] ? '?file=' . $atts['file'] : ''
);
} add_shortcode('gist','gist_shortcode');