Skip to content

Instantly share code, notes, and snippets.

View osw4l's full-sized avatar
🎹
Piano player

Oswaldo Rodriguez osw4l

🎹
Piano player
  • universidad libre de colombia
  • Barranquilla, Colombia
  • 17:25 (UTC -05:00)
View GitHub Profile
public void getOrCreateUser(final ParseUser parseUser, final String email, final ProgressDialog dialog){
String URL = "https://example.co/api/accounts?email="+ email +"&action=get_or_create";
JsonArrayRequest req = new JsonArrayRequest(URL, new com.android.volley.Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray jsonArray) {
try {
JSONObject apiUser = jsonArray.getJSONObject(0);
parseUser.put("email", email);
parseUser.put("api_token", apiUser.getString("token"));
parseUser.put("api_id", apiUser.getInt("id"));
@osw4l
osw4l / tasks.py
Last active November 9, 2016 15:47
filter content by request user
# models
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Task(models.Model):
owner = models.ForeignKey('auth.User', related_name='tasks')
completed = models.BooleanField(default=False)
import functools
from channels.handler import AsgiRequest
from rest_framework.exceptions import AuthenticationFailed
from rest_framework.settings import api_settings
authenticators = [auth() for auth in api_settings.DEFAULT_AUTHENTICATION_CLASSES]
function ajax(options) {
return new Promise(function (resolve, reject) {
$.ajax(options).done(resolve).fail(reject);
});
}
then run:
ajax({
url: YOUR_URL,
@osw4l
osw4l / celery_beat.conf
Last active January 6, 2020 05:53
deploy
[program:celery_beat]
command=/opt/env/bin/celery --app=project.celery:app beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
directory=/opt/project
user=root
stdout_logfile=/opt/logs/celery_beat/beat.log
stderr_logfile=/opt/logs/celery_beat/beat.error.log
autostart=true
autorestart=true
startsecs=10
@osw4l
osw4l / attrs_with_values.py
Last active February 14, 2018 23:12
get the number of attributes with values that an object has
class Computer(object):
name = None
serial = None
model = None
kind = None
attrs_with_value = None
def __init__(self, *args, **kwargs):
self.name = kwargs.get('name', None)
self.serial = kwargs.get('serial', None)
@shared_task
def generate_pdf(user_id, body):
user = User.objects.get(id=user_id)
files = body['new_files']
tabs = {}
for pic in files:
file = FileDetail.objects.get(filename=pic['filename'])
tab = file.story_set.get().channel.tab_set.first()
# download
scp -r osw4l@srv.domain.com:/folder ./
# upload
scp -r my_dir/ osw4l@srv.domain.com:/folder
@osw4l
osw4l / httpd.conf
Created July 30, 2018 21:49 — forked from jpalala/httpd.conf
my fedora httpd.conf
#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.2> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
@osw4l
osw4l / countryinfo.py
Created April 3, 2019 16:00 — forked from pamelafox/countryinfo.py
Python list of country codes, names, continents, capitals, and pytz timezones
countries = [
{'timezones': ['Europe/Andorra'], 'code': 'AD', 'continent': 'Europe', 'name': 'Andorra', 'capital': 'Andorra la Vella'},
{'timezones': ['Asia/Kabul'], 'code': 'AF', 'continent': 'Asia', 'name': 'Afghanistan', 'capital': 'Kabul'},
{'timezones': ['America/Antigua'], 'code': 'AG', 'continent': 'North America', 'name': 'Antigua and Barbuda', 'capital': "St. John's"},
{'timezones': ['Europe/Tirane'], 'code': 'AL', 'continent': 'Europe', 'name': 'Albania', 'capital': 'Tirana'},
{'timezones': ['Asia/Yerevan'], 'code': 'AM', 'continent': 'Asia', 'name': 'Armenia', 'capital': 'Yerevan'},
{'timezones': ['Africa/Luanda'], 'code': 'AO', 'continent': 'Africa', 'name': 'Angola', 'capital': 'Luanda'},
{'timezones': ['America/Argentina/Buenos_Aires', 'America/Argentina/Cordoba', 'America/Argentina/Jujuy', 'America/Argentina/Tucuman', 'America/Argentina/Catamarca', 'America/Argentina/La_Rioja', 'America/Argentina/San_Juan', 'America/Argentina/Mendoza', 'America/Argentina/Rio_Gallegos', 'America/Argentina/Ushuai