Skip to content

Instantly share code, notes, and snippets.

@Cariosvertel
Cariosvertel / gist:beef2e1b37e09d1df53f8a5bb44225c6
Created January 25, 2017 03:57
sample-code-to-login-on-layer
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"];
@Cariosvertel
Cariosvertel / class_serializer.py
Last active April 27, 2017 22:26
[rest_framework serializer] a sample of class definitition #tags: django, rest_framework, serializer, class
# 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):
"""
@Cariosvertel
Cariosvertel / re-start.sh
Last active April 27, 2017 22:32
[restart postgress] restar services #tags:postgres, restart
# restart
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
#stop manually
pg_ctl -D /usr/local/var/postgres stop -s -m fast
@Cariosvertel
Cariosvertel / pip-location.sh
Last active April 28, 2017 13:46
[pip packages] #tags: pip, packages, location
/Library/Python/2.7/site-packages
@Cariosvertel
Cariosvertel / package-verion.sh
Last active April 28, 2017 13:46
[package version] #tags: pip, package, version
pip freeze | grep celery
@Cariosvertel
Cariosvertel / args.py
Last active April 28, 2017 13:47
[django args] kwargs args #tags: django, kwargs, args
# contains only values passed on function invokation
*args
# contains only key-values passed on function invokation
**kwargs
# function definition and user
def table_things(*args,**kwargs):
# works normal python dictionary
user = kwargs.pop('user',None)
@Cariosvertel
Cariosvertel / raise-exception.py
Last active April 28, 2017 13:48
[rest_framework exception] raise a exception #tags: exception, rest_framework
from rest_framework import serializers
raise serializers.ValidationError({
'error': 'User already has liked this news.',
'code' : exception_handler.ERROR_DATA_INCONSISTENCY
})
@Cariosvertel
Cariosvertel / model-field.py
Last active April 28, 2017 13:48
[models fields definition] all fields definitions for a django project db model #tags: django, models, fields
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='+',
)
@Cariosvertel
Cariosvertel / bt-button-clic.java
Last active April 28, 2017 13:48
[butterknife onClick] #tags: android, butterknife, button, click
@OnClick(R.id.submit)
public void submit(View view) {
// TODO submit data to server...
}
All arguments to the listener method are optional.
@OnClick(R.id.submit)
public void submit() {
// TODO submit data to server...
@Cariosvertel
Cariosvertel / fragmentt-add.java
Last active April 28, 2017 13:48
[add fragment] add a new fragment #tags: fragment, android, add
getSupportFragmentManager()
.beginTransaction()
.add(containerViewId, fragment, fragmentTag)
.disallowAddToBackStack()
.commit();