Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Alex Pretzlav Pretz

🎯
Focusing
View GitHub Profile
@Pretz
Pretz / generate.py
Created Feb 8, 2012
CSV to WAV: Needed a way to convert a list of numbers in a CSV file to a wave audio file. Go python.
View generate.py
#!/usr/bin/python
import wave
import numpy
import struct
import sys
import csv
from scikits.samplerate import resample
def write_wav(data, filename, framerate, amplitude):
@Pretz
Pretz / gist:822036
Created Feb 11, 2011
xAuth in Android for Instapaper using Signpost
View gist:822036
protected String[] doInBackground(String... credentials) {
String consumer_secret = mActivity.getString(R.string.oauth_consumer_secret);
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost("https://www.instapaper.com/api/1/oauth/access_token");
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(mActivity.getString(R.string.oauth_consumer_key),
consumer_secret);
List<BasicNameValuePair> params = Arrays.asList(
new BasicNameValuePair("x_auth_username", credentials[0]),
new BasicNameValuePair("x_auth_password", credentials[1]),
new BasicNameValuePair("x_auth_mode", "client_auth"));
@Pretz
Pretz / uiviewcontroller-playground.swift
Created Dec 8, 2015
UIViewController Playground: because getting a UIViewController/UINavigationController to display properly in a playground is a little non-obvious
View uiviewcontroller-playground.swift
import UIKit
let vc = UIViewController()
vc.view.backgroundColor = .whiteColor()
vc.navigationItem.title = "This is a view controller"
let searchController = UISearchController(searchResultsController: nil)
//searchController.searchBar.barTintColor = UIColor(red:0.16, green:0.45, blue:0.72, alpha:1)
@Pretz
Pretz / retina_wrap.swift
Last active Nov 14, 2017
Render a view at 2x scale factor in an Xcode playground
View retina_wrap.swift
func retinaWrap(view: UIView, scaleFactor: CGFloat = 2.0) -> UIView {
let scaleTransform = CGAffineTransformMakeScale(scaleFactor, scaleFactor)
let scaledView = UIView(frame: CGRectMake(0, 0, view.bounds.width * scaleFactor, view.bounds.height * scaleFactor))
view.transform = scaleTransform
view.center = CGPoint(x: scaledView.frame.width / 2, y: scaledView.frame.height / 2)
scaledView.addSubview(view)
return scaledView
}
@Pretz
Pretz / swift-json.md
Last active Jun 21, 2017
A comparison of different JSON Object Mapping Libraries for Swift
View swift-json.md

Swift JSON Object Mappers

Argo

struct User {
  let id: Int
  let name: String
  let email: String?
  let role: Role
@Pretz
Pretz / RoundedImageView.java
Created Jan 10, 2012
Andround Rounded Image View
View RoundedImageView.java
package com.yelp.android.ui.widgets;
import com.yelp.android.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
View install-charles-ca-cert-for-iphone-simulator.command
#/bin/bash
install() {
if [ -f "$SQLITEDBPATH" ]; then
cp -n "$SQLITEDBPATH" "$SQLITEDBPATH.charlesbackup"
sqlite3 "$SQLITEDBPATH" <<EOF
INSERT INTO "tsettings" VALUES(X'189B6E28D1635F3A8325E1E002180DBA2C02C241',X'3123302106035504030C1A436861726C65732050726F78792053534C2050726F7879696E6731243022060355040B0C1B687474703A2F2F636861726C657370726F78792E636F6D2F73736C3111300F060355040A0C08584B3732204C74643111300F06035504070C084175636B6C616E643111300F06035504080C084175636B6C616E64310B3009060355040613024E5A',X'3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D225554462D38223F3E0A3C21444F435459504520706C697374205055424C494320222D2F2F4170706C652F2F44544420504C49535420312E302F2F454E222022687474703A2F2F7777772E6170706C652E636F6D2F445444732F50726F70657274794C6973742D312E302E647464223E0A3C706C6973742076657273696F6E3D22312E30223E0A3C61727261792F3E0A3C2F706C6973743E0A',X'3082045E30820346A003020102020101300D06092A864886F70D01010505003081913123302106035504030C1A436861726C65732050726F78792053534C2050726F7879696E67312430
View Duration.swift
// Playground - noun: a place where people can play
import Foundation
extension NSTimeInterval {
var seconds: NSTimeInterval {
return self
}
var minutes: NSTimeInterval {
@Pretz
Pretz / state_restoration.m
Created Nov 11, 2013
NSFetchedResultsController backed UITableViewController with State Restoration
View state_restoration.m
#pragma mark - State Restoration
- (NSString *)modelIdentifierForElementAtIndexPath:(NSIndexPath *)idx inView:(UIView *)view {
if (idx && self.fetchedResultsController) {
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:idx];
return object.objectID.URIRepresentation.absoluteString;
}
return nil;
}
@Pretz
Pretz / static_const.m
Created Oct 9, 2013
C macro for creating handy static constants in obj-c. Is this a bad or good idea?
View static_const.m
#define STATIC_CONST(name) static NSString * const name = @#name;
STATIC_CONST(LearningNavRestorationIdentifier)
STATIC_CONST(ProfileNavRestorationIdentifier)
STATIC_CONST(ReservationsNavRestorationIdentifier)
#undef STATIC_CONST
// Becomes: