Skip to content

Instantly share code, notes, and snippets.

View jbender's full-sized avatar

Jonathan Bender jbender

View GitHub Profile
@jbender
jbender / cell_layout.rb
Created April 29, 2016 17:25
MotionKit Cells
class CellLayout < MotionKit::Layout
include CommonStyles
def layout
root :cell do
add contentView, :content_view do
add(UIView, :container) { cell_content_layout }
end
end
end
@jbender
jbender / 01_set_up_client.php
Created April 5, 2016 18:43
Getting Started with Contactually API v2 - PHP
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://api.contactually.com',
'headers' => [
'Accept': 'application/json',
'Authorization': 'Bearer AUTH_TOKEN_HERE'
],
]);
@jbender
jbender / 02_get_current_user.sh
Created April 5, 2016 17:55
Getting Started with Contactually API v2 - cURL
curl https://api.contactually.com/v2/me \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-H "Content-Type: application/json"
@jbender
jbender / 01_set_up_client.py
Created April 5, 2016 17:29
Getting Started with Contactually API v2 - Python
import requests
client = http.client.HTTPSConnection('api.contactually.com')
host = 'https://api.contactually.com'
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN_HERE'
}
@jbender
jbender / 01_set_up_client.rb
Created April 5, 2016 17:16
Getting Started with Contactually API v2 - Ruby
require 'faraday'
require 'faraday_middleware'
client = Faraday.new(
url: 'https://api.contactually.com',
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN_HERE'
}
) do |connection|
@jbender
jbender / simulators.rb
Created February 23, 2016 19:35
RubyMotion simulate all OS/device combos
{
:iphone_4 => 'iPhone 4s',
:iphone_5 => 'iPhone 5',
:iphone_6 => 'iPhone 6',
:iphone_6_plus => 'iPhone 6 Plus',
:ipad => 'iPad Retina',
:ipad_air => 'iPad Air'
}.each do |rake_task, device|
default_task = "bundle exec rake device_name=\"#{device}\""
@jbender
jbender / swipable_cell.rb
Created February 11, 2016 16:38
Example RubyMotion Swipable Cell module
module SwipeableCell
ANIMATION_DURATION = 0.2
MAX_TRANSITION_ALPHA = 0.5
SWIPE_THRESHOLD = 110
LONG_SWIPE_THRESHOLD = SWIPE_THRESHOLD + 80
FADE_IN_DISTANCE = SWIPE_THRESHOLD
def gestureRecognizer(recognizer,
shouldRecognizeSimultaneouslyWithGestureRecognizer: other_recognizer)
return true unless recognizer.is_a? UIPanGestureRecognizer
@jbender
jbender / contact.rb
Created February 2, 2016 22:28
Example RubyMotion Network Model
module ContactuallyApi
module Models
class Contact < Base
include NameHelper
ATTRIBUTES = CORE_ATTRIBUTES + [
:addresses,
:avatar_url,
:company,
:email_addresses,
@jbender
jbender / contacts.rb
Created February 2, 2016 22:26
Example RubyMotion Resource
module ContactuallyApi
module Resources
module Contacts
RESOURCE_URL_BASE = 'api/v2/contacts'.freeze
def contact_index(params = nil, &block)
path = RESOURCE_URL_BASE
ContactuallyApi.client.get(path, params, &block)
end
@jbender
jbender / custom_cell.rb
Last active December 1, 2015 16:34
ProMotion::Table + Autolayout + Motion-Kit
class CustomCell < UITableViewCell
def initWithStyle(style, reuseIdentifier: identifier)
super
@layout = CustomCellLayout.new(root: WeakRef.new(self)).build
self
end
def obj=(obj)
@layout.foo = obj[:foo]
@layout.bar = obj[:bar]