Skip to content

Instantly share code, notes, and snippets.

import UIKit
class ViewController: UIViewController {
var count = 1
override func viewDidLoad() {
super.viewDidLoad()
// Button 1
@mbeaty
mbeaty / gist:7700379
Created November 29, 2013 01:31
Android ViewHolder pattern rework
An alternative to the traditional Google-recommended ViewHolder pattern. This implementation you don't have to create a ViewHolder class per view:
https://github.com/BoD/jraf-android-util/blob/master/src/org/jraf/android/util/ui/ViewHolder.java
"Example usage, in your adapter:
TextView name = ViewHolder.get(convertView, R.id.name);
(As you can see you can even skip the cast because of the generics trick.)"
@mbeaty
mbeaty / gist:1687232
Created January 27, 2012 05:42
iPhone Screenshot in code
// Capture Screenshot - Need to verify this still works in iOS 5
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data = UIImageJPEGRepresentation(screenshotImage,self.jpegCompressionRate);
NSUInteger len = [data length];
@mbeaty
mbeaty / gist:1489630
Created December 17, 2011 08:07
Deploy Android Apps from Apache Web Server
# Add this to httpd.conf
AddType application/vnd.android.package-archive .apk
# Access as
# <a href="downloads/MyApp.apk" type="application/vnd.android.package-archive">Download MyApp</a>
@mbeaty
mbeaty / gist:1263968
Created October 5, 2011 08:54
Pixel width of HTML text
An interesting approach I found (didn't invent) for determine the width of some text in an HTML document:
1) Wrap your text in a table td element:
<table><tr>
<td id="test">Some text you want to measure in pixels</td>
</tr></table>
2) Define CSS rules to reset all default/inherited table styles for the table in (1), so there is no extra padding, margin, border, etc that would affect the pixel calculation.
3) Using Javascript, get the DOM element for td element above and get it's offsetWidth property. This will be the width of the text in pixels (unaffected by font characteristics).
@mbeaty
mbeaty / gist:1263930
Created October 5, 2011 08:29
HTML text width to pixels
Source: http://stackoverflow.com/questions/118241/calculate-text-width-with-javascript
HTML:
<div id="Test">
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
</div>
CSS:
@mbeaty
mbeaty / gist:1261182
Created October 4, 2011 08:54
Google Maps fit bounds on marker and re-set zoom level
// addMarker() is just a method that creates a marker and adds it to a marker array; it returns
// the marker it just added.
var bounds = new google.maps.LatLngBounds();
var markerPos = addMarker(point.latitude, point.longitude).getPosition()
bounds.extend(markerPos);
map.fitBounds(bounds);
map.setZoom(14);
@mbeaty
mbeaty / gist:1218651
Created September 15, 2011 06:04
JSON object sort by single field
var sort_by = function(field, reverse, primer){
reverse = (reverse) ? -1 : 1;
return function(a,b){
a = a[field];
b = b[field];
if (typeof(primer) != 'undefined'){
@mbeaty
mbeaty / gist:1098985
Created July 22, 2011 06:37
Rename repo name in github
* Use Admin page for repo, then
$ git remote rm origin
$ git remote -v # should be no output
$ git remote add origin [email protected]:username/newreponame.git
$ git remote -v # to verify new origin
$ git status # verify everything looks good
Then, rename your local directory containing your repo