Skip to content

Instantly share code, notes, and snippets.

View kurtsson's full-sized avatar

Martin Kurtsson kurtsson

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')
@massive
massive / locale_diff.rb
Created November 29, 2010 13:51
Compares two YAML locale files and displays the difference
# Run: curl https://gist.github.com/raw/719970/locale_diff.rb | ruby - en fi
require 'rubygems'
require 'yaml'
l1 = ARGV[0]
l2 = ARGV[1]
first = YAML.load_file(l1 + ".yml")
second = YAML.load_file(l2 + ".yml")
def diff(root, compared, structure = [])
@sente
sente / formatXML.js
Last active April 4, 2024 12:20
javascript to format/pretty-print XML
The MIT License (MIT)
Copyright (c) 2016 Stuart Powers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@kurtsson
kurtsson / webfont.erb
Last active January 1, 2016 18:09
Ruby method that creates and imports a web font. Preferably used in an .css.scss.erb file to download the css for a Google Font statically. This saves an http request during page load.
<%
require 'net/http'
def require_web_font(o={})
o = {:family=>"Open Sans",:weights=>["500","500italic"],:url=>"http://fonts.googleapis.com/css"}.merge(o)
url = URI.parse(URI::encode("#{o[:url]}?family=#{o[:family]}:#{o[:weights] * ','}"))
Net::HTTP.start(url.host,url.port){|http| http.request(Net::HTTP::Get.new(url.to_s))}.body
end
%>
<%= require_web_font({ :family => "Droid Sans",
@kurtsson
kurtsson / env.rb
Last active August 29, 2015 14:06
Serve a static build folder using Rack when running Capybara
require 'rack_directory_index.rb'
$documentRoot = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'build'))
Capybara.app = Rack::Builder.new do |builder|
puts "Creating static rack server serving #{$documentRoot}"
use Rack::DirectoryIndex
run Rack::Directory.new($documentRoot)
end
@kurtsson
kurtsson / monkey_patch_firefox_profile.rb
Created September 30, 2014 08:40
To use a custom firefox profile for Selenium-webdriver in ruby
module Selenium
module WebDriver
module Firefox
class Profile
def layout_on_disk
firefox_profile = File.expand_path(File.join(File.dirname(__FILE__),'firefox_profile'))
profile_dir = create_tmp_copy(firefox_profile)
FileReaper << profile_dir
install_extensions(profile_dir)
@kurtsson
kurtsson / my_directive.coffee
Last active August 29, 2015 14:08
Custom Angular directive in CoffeeScript, the proper way
class MyDirective
constructor: (myService) ->
@controller = MyController
@controllerAs = myCtrl
restrict: 'E'
replace: true
scope:
attributeStuff: '='
link: (scope, element, attr) ->
// Link stuff
@gpeal
gpeal / FragmentA.kt
Last active October 2, 2024 04:10
View Binding Delegates
class WifiNetworksFragment : TonalFragment(R.layout.wifi_networks_fragment) {
// This automatically creates and clears the binding in a lifecycle-aware way.
private val binding: WifiNetworksFragmentBinding by viewBinding()
...
}
class WifiNetworkView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
import timber.log.Timber
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
class MyClass {
// This will automatically have the TAG "MyClass"
private val log by timber()
fun logSomething() {
log.i("Hello")