DispatchQueue.global(qos: .background).async {
// background things
DispatchQueue.main.async {
print("main thread dispatch")
}
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *urlString = @"api/refundo/connect_chat"; | |
NSURL *URL = [NSURL URLWithString:urlString relativeToURL:self.baseURL]; | |
NSDictionary *parameters = @{@"nonce": nonce, | |
@"user_id":[self getTaxPayerEmail]}; | |
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; | |
request.HTTPMethod = @"POST"; | |
request.HTTPBody = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil]; | |
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getSupportFragmentManager() | |
.beginTransaction() | |
.add(containerViewId, fragment, fragmentTag) | |
.disallowAddToBackStack() | |
.commit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
date_joined = models.DateTimeField(help_text=('date joined'), default=timezone.now) | |
company = models.CharField(max_length=200, blank=True, null=True, | |
help_text=("Current company user is working for"), | |
) | |
# foreign key with no related name | |
user = models.ForeignKey( | |
User, | |
on_delete=models.CASCADE, | |
related_name='+', | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# simple class with no models mappings | |
class LayerAuthSerializer(serializers.Serializer): | |
nonce = serializers.CharField() | |
display_name = serializers.CharField(required=False) | |
avatar_url=serializers.CharField(required=False) | |
# a complex class definition | |
class CreateUserSerializer(serializers.Serializer): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import serializers | |
raise serializers.ValidationError({ | |
'error': 'User already has liked this news.', | |
'code' : exception_handler.ERROR_DATA_INCONSISTENCY | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#limit | |
Entry.objects.all()[:5] | |
# limit and offset | |
# 5 offset, 10 limit | |
Entry.objects.all()[5:10] | |
#sort latest by pub_date property | |
Entry.objects.filter(pub_date__isnull=False).latest('pub_date') | |
#return first object of the query |
OlderNewer