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 / 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/ }
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: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';
}
@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 / 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 / AcitivityMixin.swift
Last active April 9, 2016 15:56
Swift Activity View Mixin
//use whatever activity view makes you happy in this project we were converting from ObjC to Swift, #2016
protocol ActivityVC: class {
var activityView: DejalBezelActivityView? { get set }
var view: UIView! { get }
}
extension ActivityVC {
mutating func activityStart() {
if activityView == nil {
activityView = DejalBezelActivityView(forView: view, withLabel: nil, width: 40)
// copy and paste into play ground
import UIKit
protocol ListViewModel {
associatedtype T:Comparable
var items: [T] { get set }
mutating func clear()
func item(forIndex index: NSIndexPath) -> T
@pedantix
pedantix / bar.ex
Last active February 19, 2017 04:08
Using cast/3 with @optional_fields and @required_fields for simplicity
defmodule Splife.Bar do
use Splife.Web, :model
schema "bars" do
field :baz, :string
field :fizz, :string
timestamps()
end
@pedantix
pedantix / String.swift
Last active October 10, 2017 19:04
truncate by words swift 4
//
// String.swift
// MyModule
//
// Created by Shaun Hubbard on 10/9/17.
// Copyright © 2017 MyCompany, LLC. All rights reserved.
//
import Foundation
@pedantix
pedantix / makeUrlReq.swift
Created October 28, 2017 02:26
Swift 4 Encapsulate the URLRequests
// I needed to make a gist to show some things off and whats nots
import Foundation
enum HttpMethod: String {
case get = "GET"
case post = "POST"
case patch = "PATCH"
case delete = "DELETE"
}