Skip to content

Instantly share code, notes, and snippets.

View pedantix's full-sized avatar
😍
SWIFT!

Shaun Hubbard pedantix

😍
SWIFT!
View GitHub Profile
@pedantix
pedantix / String.swift
Created March 27, 2016 02:11
How to add ruby-ish property accessors to String in swift that I find myself using a lot
extension String {
var blank: Bool {
get {
let trimmed = self.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
return trimmed.isEmpty
}
}
var present: Bool {
get{
@pedantix
pedantix / rake_thing_spec.rb
Created March 8, 2016 03:01
RSpec for Rake
## Rake task test cheat sheet
require "rails_helper"
require "rake"
describe "cleanup" do
before :all do
Rake.application.rake_require "tasks/cleanup"
@pedantix
pedantix / gist:b37294cb722ee3f32024
Last active August 29, 2015 14:13
Dynamic Templating in Angular.Dart 1.0.0
@NgComponent(
selector: 'my-component',
template: '<div ng-include="{{cmp.templateURL}}"></div>',
publishAs: 'cmp'
)
class MyComponent {
String get templateURL => 'packages/project/components/my_component.html';
}
def show_me_a_screenshot
if Capybara.current_driver == :webkit
name = "screen-shot-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.png"
tmp_dir = File.join(Rails.root, 'tmp')
FileUtils.mkdir_p tmp_dir
file_name = File.join(tmp_dir, name)
page.driver.save_screenshot file_name
Launchy.open file_name
end
end
@pedantix
pedantix / gist:b7727c4153d6f9aa006e
Created May 13, 2014 23:17
Slugger For Use With With FriendlyID gem
module Slugger
extend ActiveSupport::Concern
included do
validates :title, uniqueness: true,
presence: true,
length: 3..50
validates :slug, presence: true,
format: { with: /\A[a-zA-Z0-9-]+\z/ }