Skip to content

Instantly share code, notes, and snippets.

View Mexarm's full-sized avatar
🎯
Focusing

Armando H Mexarm

🎯
Focusing
  • Mexico
View GitHub Profile
@Mexarm
Mexarm / forms.py
Created June 16, 2022 03:05 — forked from maraujop/forms.py
django-crispy-forms bootstrap form example
# -*- coding: utf-8 -*-
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field
from crispy_forms.bootstrap import AppendedText, PrependedText, FormActions
class MessageForm(forms.Form):
text_input = forms.CharField()
@Mexarm
Mexarm / bash.sh
Created May 1, 2021 04:34 — forked from wikiti/bash.sh
Backup and restore in PostgreSQL using compressed backups.
# List databases
sudo su postgres
psql
\list
# Create a compressed backup
sudo su postgres
pg_dump -Fc <database_name> > <file>
# Example
@Mexarm
Mexarm / models.py
Created March 28, 2021 15:50 — forked from jacobian/models.py
An example of using many-to-many "through" to augment m2m relationships. See http://www.quora.com/How-do-you-query-with-a-condition-on-a-ManyToMany-model-in-Django for context.
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=200)
groups = models.ManyToManyField('Group', through='GroupMember', related_name='people')
class Meta:
ordering = ['name']
def __unicode__(self):
@Mexarm
Mexarm / rest-server.py
Created August 13, 2020 17:58 — forked from miguelgrinberg/rest-server.py
The code from my article on building RESTful web services with Python and the Flask microframework. See the article here: http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
#!flask/bin/python
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask_httpauth import HTTPBasicAuth
app = Flask(__name__, static_url_path = "")
auth = HTTPBasicAuth()
@auth.get_password
def get_password(username):
if username == 'miguel':
@Mexarm
Mexarm / forms.py
Created June 16, 2019 00:47 — forked from joshkehn/forms.py
Ingredient ModelForm (Django)
from django import forms
from menu.models import Ingredient, Diet, FoodPreference
class IngredientForm (forms.ModelForm):
class Meta:
model = Ingredient
exclude = ["franchise"]
def __init__ (self, *args, **kwargs):
brand = kwargs.pop("brand")
@Mexarm
Mexarm / nodejs-custom-es6-errors.md
Created June 18, 2018 16:32 — forked from slavafomin/nodejs-custom-es6-errors.md
Custom ES6 errors in Node.js

Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.

I've tried to make it as lean and unobtrusive as possible.

Defining our own base class for errors

errors/AppError.js

@Mexarm
Mexarm / setup-web2py-raspberry.sh
Created January 16, 2017 18:17
install all modules need to run web2py on Rapsberry Pi Jessie Minimal and other tools
#!/bin/bash
echo "This script will:
1) install all modules need to run web2py on Jessie Minimal and other tools
2) install web2py in /home/www-data/
3) create a self signed ssl certificate
4) setup web2py with mod_wsgi
5) overwrite /etc/apache2/sites-available/default
6) restart apache.
Press a key to continue...[ctrl+C to abort]"