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 / button-selected.xml
Last active April 28, 2017 13:49
[hola] una descripcion #tags: android, button, selected
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/numpad_button_bg_selected" android:state_selected="true"></item>
<item android:drawable="@drawable/numpad_button_bg_pressed" android:state_pressed="true"></item>
<item android:drawable="@drawable/numpad_button_bg_normal"></item>
</selector>
@Cariosvertel
Cariosvertel / gcd-swift.md
Last active November 13, 2019 12:22
[multithreading] run on background thread #tags: swift, gcd, thread

Swift

Background

DispatchQueue.global(qos: .background).async {
    // background things
    DispatchQueue.main.async {
        print("main thread dispatch")
    }
}
@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();
@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 / 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 / sublime-shortcuts.md
Last active May 8, 2018 14:32
[sublime shortcut] all shorcuts for sublime text #tags: sublimetext, shortcut

open package manager

cmd+shift+p

show console

ctrl + `

go to a line

ctrl + g

apply json format

@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 / 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 / limit-offset.py
Last active April 28, 2017 21:42
[django database] limit and offset #tags:django, limit,offset, sort, latest, first
#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