Skip to content

Instantly share code, notes, and snippets.

@dlo
dlo / Auto-layout-keyboard-adjustment.md
Last active February 26, 2021 07:33
How to adjust a view's height with Auto Layout when a keyboard appears or disappears in iOS 7.

This gist outlines how to resize a view when a keyboard appears using Auto Layout (there are a bunch of code samples out there that manually adjust the view's frame, but that's just so 2013). The method I outline below works universally on both iPhone and iPad, portrait and landscape, and is pretty darn simple.

Setting Up

The first thing to do is to define our containing view controller, the view, and the bottom constraint that we'll use to adjust its size.

Here's HeightAdjustingViewController.h. We don't need to expose any public properties, so it's pretty bare.

@mattt
mattt / uiappearance-selector.md
Last active March 19, 2024 12:52
A list of methods and properties conforming to `UIAppearance` as of iOS 12 Beta 3

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep UI_APPEARANCE_SELECTOR ./*     | \
  sed 's/NS_AVAILABLE_IOS(.*)//g'     | \
  sed 's/NS_DEPRECATED_IOS(.*)//g'    | \
  sed 's/API_AVAILABLE(.*)//g'        | \
  sed 's/API_UNAVAILABLE(.*)//g'      | \
 sed 's/UI_APPEARANCE_SELECTOR//g' | \
@Gozala
Gozala / TwitterAuthentication.lua
Created January 2, 2013 01:19
Twitter OAuth Authentication Routines in Lua, for Lightroom Plugins From: http://regex.info/blog/lua/twitter
--
-- Sending Twitter Tweets from a Lightroom Plugin
-- http://regex.info/blog/lua/twitter
--
--
-- Copyright 2009-2010 Jeffrey Friedl
-- (jfriedl@yahoo.com)
-- http://regex.info/blog/
--
-- Version 5 (Dec 17, 2010)
@julien51
julien51 / rss-to-tumblr.lua
Created December 5, 2012 21:16
An example of how to post content to a Tumblr blog with Lua. Usable in Webscript.io
local tumblrName = "" -- Name of the Tumblr blog where the content will be posted
-- Extrat the data from the JSON notification and prepare it to be used as a Tumblr 'quote'.
local jsonContent = json.parse(request.body)
local quote = jsonContent.items[1].title
local sourceTitle = jsonContent.title
local sourceLink = jsonContent.standardLinks.self[1].href
-- Authenication against the Tumblr API. You will need to create an application and grab the OAuth access token.
@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article < ActiveRecord::Base
@clarkware
clarkware / lyrics.rb
Created September 10, 2012 20:05
Random Lyrics
#!/usr/bin/env ruby
# API Documentation at http://api.wikia.com/wiki/LyricWiki_API
require 'open-uri'
require 'json'
require 'tmpdir'
ARTIST = "Johnny Cash"
@boone
boone / fix_sql_injection.rb
Created June 13, 2012 03:42
Monkey patch for CVE-2012-2695 on Rails 2.3.14
# Monkey patch for CVE-2012-2695 on Rails 2.3.14
# put this file in your config/initializers directory
# comments/corrections: https://gist.github.com/2921706
# Ruby on Rails SQL Injection
# based on a patch from @presidentbeef
# https://rubyonrails-security.googlegroups.com/attach/aee3413fb038bf56/2-3-sql-injection.patch?view=1&part=3
module ActiveRecord
class Base
@boone
boone / strip_nil_from_parameters.rb
Created June 1, 2012 18:08
Monkey patch for CVE-2012-2660 and CVE-2012-2694 on Rails 2.3.14
# Monkey patch for CVE-2012-2660 and CVE-2012-2694 on Rails 2.3.14
# put this file in your config/initializers directory
# comments/corrections: https://gist.github.com/2854095
# Strip [nil] from parameters hash
# based on a pull request from @sebbacon
# https://github.com/rails/rails/pull/6580
module ActionController
class Request < Rack::Request
@wojtekmach
wojtekmach / account_test.rb
Created May 3, 2012 09:45
Writing MiniTest extensions
require 'minitest/autorun'
module MiniTest::Assertions
def assert_changes(obj, method, exp_diff)
before = obj.send method
yield
after = obj.send method
diff = after - before
assert_equal exp_diff, diff, "Expected #{obj.class.name}##{method} to change by #{exp_diff}, changed by #{diff}"
@abner
abner / minitest_spec_expectations.md
Created March 24, 2012 00:34 — forked from ordinaryzelig/minitest_spec_expectations.md
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations