Skip to content

Instantly share code, notes, and snippets.

View paulofierro's full-sized avatar

Paulo Fierro paulofierro

View GitHub Profile
@paulofierro
paulofierro / smartBanner.js
Created July 13, 2015 23:12
iOS Smart App Banner snippet for Squarespace pages
<script>
var meta = document.createElement('meta');
meta.name = 'apple-itunes-app';
meta.content = 'app-id=XXX, affiliate-data=YYY';
document.getElementsByTagName('head')[0].appendChild(meta);
</script>
@paulofierro
paulofierro / wkwebview_disable_callouts.m
Created July 13, 2015 22:43
Disable callouts in WKWebView
// Remember to @import WebKit at the top of the class
// Javascript that disables pinch-to-zoom by inserting the HTML viewport meta tag into <head>
NSString *source = @"var style = document.createElement('style'); \
style.type = 'text/css'; \
style.innerText = '*:not(input):not(textarea) { -webkit-user-select: none; -webkit-touch-callout: none; }'; \
var head = document.getElementsByTagName('head')[0];\
head.appendChild(style);";
WKUserScript *script = [[WKUserScript alloc] initWithSource:source injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
@paulofierro
paulofierro / wkwebview_disable_magnification.swift
Created January 27, 2015 14:26
Disable magnification in WKWebView using Swift
// Remember to @import WebKit at the top of the class
// Javascript that disables pinch-to-zoom by inserting the HTML viewport meta tag into <head>
let source: NSString = "var meta = document.createElement('meta');" +
"meta.name = 'viewport';" +
"meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';" +
"var head = document.getElementsByTagName('head')[0];" +
"head.appendChild(meta);";
let script: WKUserScript = WKUserScript(source: source, injectionTime: .AtDocumentEnd, forMainFrameOnly: true)
@paulofierro
paulofierro / wkwebview_disable_magnification.m
Last active March 13, 2020 16:11
Disable magnification in WKWebView
// Remember to @import WebKit at the top of the class
// Javascript that disables pinch-to-zoom by inserting the HTML viewport meta tag into <head>
NSString *source = @"var meta = document.createElement('meta'); \
meta.name = 'viewport'; \
meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'; \
var head = document.getElementsByTagName('head')[0];\
head.appendChild(meta);";
WKUserScript *script = [[WKUserScript alloc] initWithSource:source injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
@paulofierro
paulofierro / s3_gzip.rb
Last active August 29, 2015 13:57
Compressing JSON on S3
require 'zlib'
require 'stringio'
# Connect to the bucket and create the file
s3 = AWS::S3.new(access_key_id: 'S3_ACCESS_KEY', secret_access_key: 'S3_SECRET_KEY', region: 'S3_REGION')
bucket = s3.buckets['S3_BUCKET']
file = bucket.objects.create('S3_FILE_NAME', '')
# Set the content type and encoding. This is the important bit
options = {:acl => :public_read, :content_type => 'application/json', :content_encoding => 'gzip'}
@paulofierro
paulofierro / TODO & FIXME Warnings
Last active June 28, 2016 17:58
Turns // TODO: and // FIXME: into warnings when added as a build phase to an Xcode project.
#!/bin/sh
KEYWORDS="TODO:|VERIFY:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" -not -path "${SRCROOT}/Pods/*" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"
@paulofierro
paulofierro / convert.sh
Last active June 4, 2016 02:31
Convert WAV to CAF
##
## Shell script to batch convert all files in a directory to caf sound format for iPhone
## Place this shell script a directory with sound files and run it: 'sh afconvert_wavtocaf.sh'
##
## If only converting one then:
## afconvert -f caff -d ima4 FILENAME.WAV
##
## Via http://stackoverflow.com/questions/8769851/convert-multiple-wav-to-caf
for f in *.wav; do
@paulofierro
paulofierro / Xcode Snippets.md
Last active August 29, 2015 13:55
Xcode snippets that I always forget how to type.

Block properties

@property (nonatomic, copy) void (^myBlock)(void);
@property (nonatomic, copy) void (^myBlock)(NSString *parameter);

Block variables

void (^myBlock)() = ^()
{

NSLog(@"Do something");

<html>
<head>
<title>Token viewer</title>
<style>
body {
text-align:center;
font-family:'Helvetica Neue';
}
</style>
</head>