Skip to content

Instantly share code, notes, and snippets.

View shawnpk's full-sized avatar

Shawn Kearney shawnpk

View GitHub Profile
@shawnpk
shawnpk / iterm2.md
Created June 19, 2022 14:18 — forked from squarism/iterm2.md
An iTerm2 Cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
@shawnpk
shawnpk / person.rb
Created October 29, 2020 17:53 — forked from davidbella/person.rb
Ruby: Dynamic meta-programming to create attr_accessor like methods on the fly
class Person
def initialize(attributes)
attributes.each do |attribute_name, attribute_value|
##### Method one #####
# Works just great, but uses something scary like eval
# self.class.class_eval {attr_accessor attribute_name}
# self.instance_variable_set("@#{attribute_name}", attribute_value)
##### Method two #####
# Manually creates methods for both getter and setter and then
@shawnpk
shawnpk / rspec_model_testing_template.rb
Created September 13, 2020 04:39 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@shawnpk
shawnpk / abba-babba.md
Last active March 16, 2020 03:10 — forked from pixelcandy/abba-babba.md
Brief Ruby Challenge

Instructions

  • Fork this gist.
  • Please complete the quick challenge below using Ruby, uploading additional files if necessary.
  • Reply back to the email you were sent with the link to your completed gist.

Abba Babba Binary Challenge

def recursive_array_flatten(array, results = [])
array.each do |element|
if element.class == Array
recursive_flatten(element, results)
else
results << element
end
end
results
end

Keybase proof

I hereby claim:

  • I am shawnpk on github.
  • I am shawnpk (https://keybase.io/shawnpk) on keybase.
  • I have a public key ASDY_vGOLhpGNHU6Xs58WNgauJiG9nvEB9jCWykvWsHhhgo

To claim this, I am signing this object:

@shawnpk
shawnpk / capybara cheat sheet
Created August 6, 2016 18:58 — 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')
@shawnpk
shawnpk / rspec_rails_cheetsheet.rb
Created June 26, 2016 15:34 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@shawnpk
shawnpk / webserver.js
Created June 5, 2016 21:10 — forked from hectorcorrea/webserver.js
web server in node.js
// A very basic web server in node.js
// Stolen from: Node.js for Front-End Developers by Garann Means (p. 9-10)
var port = 8000;
var serverUrl = "127.0.0.1";
var http = require("http");
var path = require("path");
var fs = require("fs");

Contract Killer

The popular open-source contract for web designers and developers by Stuff & Nonsense

  • Originally published: 23/12/2008
  • Revised date: 15/12/2013
  • Original post