Skip to content

Instantly share code, notes, and snippets.

@darcwader
darcwader / .gitignore
Last active December 16, 2015 06:49
Objective-C Gitignore file
# OS X temporary files that should never be committed
.DS_Store
*.swp
*.lock
profile
# Xcode temporary files that should never be committed
*~.nib
# Xcode build files -
@darcwader
darcwader / gist:5721194
Created June 6, 2013 12:38
This calculates the height of webview based on the html page.
NSMutableString *js = [NSMutableString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"individualnotification" ofType:@"js"] encoding:NSUTF8StringEncoding error:nil];
    [js appendString:@"getHeightForElementById(\"idNotificationContent\")"];
    
    float height = [[contentWebView stringByEvaluatingJavaScriptFromString:js] floatValue];
function getHeightForElementById(elementID) {
    var height = 0;
var subElements = Array();
    var element = document.getElementById(elementID);
@darcwader
darcwader / gist:5721712
Created June 6, 2013 13:59
Rotation Animation using Core Animation
CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0/700.0;
transform = CATransform3DRotate(transform, M_PI, 0, 1, 0);
CATransform3D transform2 = CATransform3DRotate(transform, -M_PI/2, 0, 1, 0);
CATransform3D transform3 = CATransform3DRotate(transform2, -M_PI/2, 0, 1, 0);
CALayer *layer = self.cardView.layer;
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform"];
rotation.fromValue = [NSValue valueWithCATransform3D:transform];
rotation.toValue = [NSValue valueWithCATransform3D:transform2];
@darcwader
darcwader / json-additional-fields.go
Created August 18, 2016 06:57
golang keeping additional json fields as is
package main
import (
"encoding/json"
"fmt"
)
func main() {
str := `{"hello":{"nested":{"world":"!"}}}`
fmt.Println("input string : ", str)
@darcwader
darcwader / resize-cg.swift
Created August 30, 2016 02:35
Resizing Image using CoreGraphics
extension UIImage {
func resizeCG(size:CGSize) -> UIImage? {
let bitsPerComponent = CGImageGetBitsPerComponent(self.CGImage)
let bytesPerRow = CGImageGetBytesPerRow(self.CGImage)
let colorSpace = CGImageGetColorSpace(self.CGImage)
let bitmapInfo = CGImageGetBitmapInfo(self.CGImage)
let context = CGBitmapContextCreate(nil, Int(size.width), Int(size.height), bitsPerComponent, bytesPerRow, colorSpace, bitmapInfo.rawValue)
CGContextSetInterpolationQuality(context, .High)
@darcwader
darcwader / flickr_interesting.m
Created January 28, 2017 13:54
Flickr Interesting Image building
//https://api.flickr.com/services/rest/?method=flickr.interestingness.getList&api_key=aa621a9050ef8dfbd9621cc311da86aa&format=json
-(NSString*) flickrInterestingGenerateUrlFromInfo:(NSDictionary*) info {
return [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_t.jpg",
[info objectForKey:@"farm"],
[info objectForKey:@"server"],
[info objectForKey:@"id"],
[info objectForKey:@"secret"]];
}
@darcwader
darcwader / git_credential_ubuntu.sh
Created August 30, 2017 05:58
How to enable git to store password in ubuntu
sudo apt-get install libgnome-keyring-dev
sudo make --directory=/usr/share/doc/git/contrib/credential/gnome-keyring
git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
@darcwader
darcwader / DataCoordinator.swift
Last active October 11, 2017 05:28
Core Data Coordinator for iOS 11 Apps
final class DataCoordinator {
//MARK: - singleton
private static var coordinator: DataCoordinator?
public class func sharedInstance() -> DataCoordinator {
if coordinator == nil {
coordinator = DataCoordinator()
}
return coordinator!
}
@darcwader
darcwader / spam_001.py
Last active October 29, 2017 12:56
spam
file_name = 'SMSSpamCollection'
with open(file_name) as f:
corpus = f.readlines()
print("there are {} messages".format(len(corpus)))
corpus = [x.strip() for x in corpus] #remove trailing \n from lines
for i,message in enumerate(corpus[:10]):
print(i, message)
@darcwader
darcwader / spam_002.py
Created October 29, 2017 12:57
spam 2
with open('SMSSpamCollection',encoding='UTF-8') as f:
messages = pd.read_csv(f, sep='\t', quoting=csv.QUOTE_NONE, names=['label', 'message'])
messages['message'] = messages['message'].map(lambda text:text.decode(encoding='utf-8'))
messages.head()