Skip to content

Instantly share code, notes, and snippets.

#Django 10.1 on Python 3.5
#main credit to http://stackoverflow.com/users/2089197/kevin-stone
#sub credit to http://stackoverflow.com/users/3694224/kerryz
#Questions or problems please reach me at hammadzz on github
#The serializers are timezone aware, they will check the timezone of the datetimefield object and serialize to a unix epoch timestamp (it is always in UTC). The magic piece that makes it work correctly is calendar.timegm()
#Add these serializers in serializers.py, the best practice is to make a new Django app called utils, and create a serializers.py file there which contains the code in this snippet. I have included an example using it below:
#utils/your-django-project/utils/serializers.py
from rest_framework import serializers
- (NSString *)stringWithDeviceToken:(NSData *)deviceToken {
const char *data = [deviceToken bytes];
NSMutableString *token = [NSMutableString string];
for (NSUInteger i = 0; i < [deviceToken length]; i++) {
[token appendFormat:@"%02.2hhX", data[i]];
}
return [token copy];
}
//Put this line in application did finish launching
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:[UIColor whiteColor]];
[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
//Another option
//Also use this to prevent to Cancel button text on the popup to disappear
[activityController.view setTintColor:[UIColor redColor]];
@hammadzz
hammadzz / raisedTabBarIcon.swift
Created January 12, 2017 03:49
Raised Icon on RAMAnimatedTabBar
let item: RAMAnimatedTabBarItem = self.tabBarItem as! RAMAnimatedTabBarItem
for constraint in (item.iconView!.icon.superview?.constraints)! {
if let currentView: UIImageView = constraint.firstItem as? UIImageView {
if item.iconView!.icon == currentView {
if constraint.firstAttribute == .centerY {
constraint.constant = -10;
}
}
}
@hammadzz
hammadzz / TabBarBackToTop.swift
Created January 12, 2017 03:51
TabBar Pressing Button Brings it Back to Top of ScrollView
class tapBarController: UITabBarController, UITabBarControllerDelegate {
/// Determines whether the scrolling capability's enabled.
var scrollEnabled: Bool = true
private var previousIndex = 0
override func viewDidLoad() {
super.viewDidLoad()
@hammadzz
hammadzz / allow_arbitrary_loads.plist
Last active January 13, 2017 03:55
NS App Transport Security Plist Exceptions
<!-- Disables ATS for any domains -->
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
@hammadzz
hammadzz / ReportCrashlyticsError.m
Created January 18, 2017 15:56
Reporting Crashlytics Error
#import "ViewController.h"
#import <Crashlytics/Crashlytics.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)logCustomInfo
{
CLS_LOG(@"Logging custom info!");
@hammadzz
hammadzz / Runscript
Created January 26, 2017 05:32
Crashlytics Runscript
if [ "${CONFIGURATION}" = "Release" ]; then
"${PODS_ROOT}/Fabric/run" <release API Key> <release Build Secret>
else
"${PODS_ROOT}/Fabric/run" <debug API Key> <debug Build Secret>
fi
/// Clear status bar
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
@hammadzz
hammadzz / list_users_script.py
Created February 1, 2017 22:30
List users on django
from django.contrib.auth import get_user_model
UserModel = get_user_model()
UserModel.objects.all()