Skip to content

Instantly share code, notes, and snippets.

@mcgaffin
mcgaffin / gist:3873928
Created October 11, 2012 17:03
iOS: how to get the ip address of a remote host.
// adapted from: http://blog.zachwaugh.com/post/309927273/programmatically-retrieving-ip-address-of-iphone
- (NSString *)getIPAddress {
Boolean result;
CFHostRef hostRef;
CFArrayRef addresses;
NSString *hostname = @"domain.myhost.com";
NSString *ipAddress = @"";
hostRef = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef)hostname);
if (hostRef) {
@mcgaffin
mcgaffin / gist:4001580
Created November 2, 2012 14:13
Here's how you implement autorotate conditionally when your view is in a UINavigationController
// This is inside a subclass of UINavigationController that has been set as the root view of the app.
- (BOOL)shouldAutorotate
{
if ([self.topViewController isKindOfClass:[DetailViewController class]]) {
return [self.topViewController shouldAutorotate];
}
return NO;
}
@mcgaffin
mcgaffin / gist:19b7127a6fc41428487b
Created December 24, 2014 16:30
zsh script for creating a bunch of repos
#!/usr/local/bin/zsh
for (( num=1; num <= 500; num++ ))
do
echo "${num}"
curl -X POST -H "Authorization: Basic <personal_access_token_goes_here>" -H "Cache-Control: no-cache" -d "{\"name\":\"repo${num}\", \"auto_init\": true}" https://api.github.com/orgs/codeshiptest/repos
done
@mcgaffin
mcgaffin / gist:936ee5da26733a42af11
Last active August 29, 2015 14:13
Deploy only changed files to ftp
# submitted by a user via intercom: https://app.intercom.io/a/apps/hb7wi6ch/inbox/unassigned/conversations/681962001
mkdir ~/clone/git_clone
mkdir ~/clone/changes_only
cd ~/clone/git_clone
git clone https://username:password@repo
cd ~/clone/git_clone/repo
tar cf - $(git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $COMMIT_ID) | ( cd ~/clone/changes_only; tar xpf -)
lftp -c "open -u $FTP_USER,$FTP_PASSWORD 31.186.174.218; set ssl:verify-certificate no; mirror -R ~/clone/changes_only/ /remote_dir"
@mcgaffin
mcgaffin / gist:07abe373f202ace896f2
Last active August 29, 2015 14:16
meteor installation on codeship
nvm use 0.10.36
curl -o meteor_install_script.sh https://install.meteor.com/
chmod +x meteor_install_script.sh
sed -i "s/type sudo >\/dev\/null 2>&1/\ false /g" meteor_install_script.sh
./meteor_install_script.sh
@mcgaffin
mcgaffin / section_headers.md
Last active August 29, 2015 14:27
React Native: add section headers to ListView

from facebook/react-native#1706

First I put this in my constructor function:

var getSectionData = (dataBlob, sectionID) => {
      return dataBlob[sectionID];
 }
var getRowData = (dataBlob, sectionID, rowID) => {
      return dataBlob[sectionID + ':' + rowID];

Keybase proof

I hereby claim:

  • I am mcgaffin on github.
  • I am bookbubdavid (https://keybase.io/bookbubdavid) on keybase.
  • I have a public key whose fingerprint is 82D4 DB39 4888 8B56 61A1 86FE CF3B 0136 81B5 564A

To claim this, I am signing this object:

@mcgaffin
mcgaffin / javascript_copy.md
Last active January 15, 2016 19:14
javascript: copy text to the clipboard

html

<a id='copy_btn'>Copy</a>

js

var copy_btn = document.getElementById('copy_btn')
copy_btn.addEventListener('click', function(event) {
@mcgaffin
mcgaffin / days_of_month.sql
Last active June 15, 2016 13:28
Find number of days in any month modded by some day-of-month
postgresql
----
select 31 % (SELECT
DATE_PART(
'days',
DATE_TRUNC('month', now() :: DATE) + '1 MONTH' :: INTERVAL - '1 DAY' :: INTERVAL
)
)::integer
redshift
@mcgaffin
mcgaffin / jq.md
Last active August 4, 2016 16:22
Querying json with jq

Install jq

$ brew install jq

Simple Querying

With json that looks like this:

[
  [