Skip to content

Instantly share code, notes, and snippets.

View hsuh's full-sized avatar
🦕

Hsu Hlaing hsuh

🦕
  • Edinburgh
  • 20:03 (UTC -12:00)
View GitHub Profile
@hsuh
hsuh / gist:f0c77bbe16392686d556
Created January 8, 2015 12:13
cygwin cd-ing into files and folders with spaces
e.g. cd Program*Files/
cd Program\ Files\ \(x86\)
In your .bashrc
alias cdc='cd /cygdrive/c'
alias cdp='cd /cygdrive/c/Program*Files/'
alias cdpx='cd /cygdrive/c/Program\ Files\ \(x86\)'
=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')
@hsuh
hsuh / gist:4381cc0d5d1b8f75f864
Created October 30, 2014 10:11
if your rails console word wrap disappeared while on screen
it's probably screen
Ctrl + a
Ctrl + r
until it says +wrap
@hsuh
hsuh / gist:8405170e27f1130ce107
Created October 2, 2014 11:49
capybara select by value
def select_by_value(id, value)
option_xpath = "//*[@id='#{id}']/option[@value='#{value}']"
option = find(:xpath, option_xpath).text
select(option, :from => id)
end
Save in a .rb file in spec/support/ (Optional)
Example use:
before do
@hsuh
hsuh / country_select_helper.rb
Created September 17, 2014 10:22
country_select fix for Rails 3.2
class CountrySelect < InstanceTag
include ::CountrySelect::TagHelper
def render(options, html_options)
@options = options
@html_options = html_options
if self.respond_to?(:select_content_tag)
select_content_tag(country_option_tags, @options, @html_options)
else
@hsuh
hsuh / gist:913bf4210e9f3f32fe4e
Created September 2, 2014 11:09
Grep colours
In your .bashrc file
export GREP_OPTIONS='--color=always'
@hsuh
hsuh / svg_foreignobj
Last active August 29, 2015 14:05
svg foreignobject
<?xml version="1.0" standalone="yes"?>
<svg xmlns = "http://www.w3.org/2000/svg" width="100%" height="100%">
<rect x="25" y="25" width="250" height="200" fill="#ff0000" stroke="#000000"/>
<foreignObject x="50" y="50" width="200" height="150">
<body xmlns="http://www.w3.org/1999/xhtml">
<form>
<input type="text"/>
<input type="text"/>
</form>
</body>
When using ng-class, the expression must evaluate to one of the following:
a string of space-delimited class names, or
and array of class names, or
a map/object of class names to boolean values.
@hsuh
hsuh / screen.md
Last active October 16, 2015 18:44
screen spliting with screen

In screen the terminal multiplexer.

  • To split vertically: ctrl a then |.
  • To split horizontally: ctrl a then S (uppercase one).
  • To unsplit: ctrl a then Q (uppercase one).
  • To switch from one to the other: ctrl a then tab

Note: After splitting, you need to go into the new region and start a new session via ctrl a then c before you can use that area.

@hsuh
hsuh / binding
Last active August 29, 2015 14:02
Biding events to dynamically created html elements
Here is what gets you all the way:
$(document).ready(function() {
$(document).on("click","textarea",function(){
// Do something when textarea is clicked
});
});
If your app is like most web apps, it is probably full of AJAX. Suppose you have a page that renders some buttons or links but it also dynamically adds more of those elements as events happen, such as an AJAX pagination event. To top it off, all those elements have events tied to them (think hitting "Like" on a friends Facebook post that was not initially visible on the page.").