Skip to content

Instantly share code, notes, and snippets.

View rbtsolis's full-sized avatar
👨‍💻

Roberth Solís rbtsolis

👨‍💻
View GitHub Profile
@rbtsolis
rbtsolis / middleware.py
Created May 3, 2018 02:46
Django Access the Request or User Object Inside the Models and Signals
# 1) Create a middlewares/middlewares.py file and copy this:
import threading
class RequestMiddleware:
def __init__(self, get_response, thread_local=threading.local()):
self.get_response = get_response
self.thread_local = thread_local
# One-time configuration and initialization.
from django.db import models
from simple_history.models import HistoricalRecords
from django.utils.translation import ugettext_lazy as _
class GetOrNoneManager(models.Manager):
"""
Adds get_or_none method to objects
"""
def get_object_or_none(self, default_value=None, *args, **kwargs):
APP_NAME='Hotel El Pueblo'
APP_ENV=local
APP_KEY=base64:y2eRdQynPR8l6vJUlNsO+1IiMUTB45ZdVjiFDi8v2SU=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
@rbtsolis
rbtsolis / language.py
Created October 13, 2017 19:57 — forked from beaufour/language.py
Django Middleware to choose language based on subdomain
import logging
from django.utils import translation
class SubdomainLanguageMiddleware(object):
"""
Set the language for the site based on the subdomain the request
is being served on. For example, serving on 'fr.domain.com' would
make the language French (fr).
var fs = require('fs'),
path = require('path'),
child_process = require('child_process');
function watchStyles(sourcefile, destinationfolder) {
var Stylus = child_process.spawn('stylus', ['-c','-u','nib','-w', sourcefile, '--out', destinationfolder]);
Stylus.stdout.pipe(process.stdout); // notifications: watching, compiled, generated.
var fs = require('fs'),
path = require('path');
function watchStyles(sourcefile, destinationfolder) {
var exec = require('child_process').exec;
var cmd = `stylus -c -u nib -w ${sourcefile} -o ${destinationfolder}`;
exec(cmd, function(error, stdout, stderr) {
if (stdout) {
console.log(stdout);
@rbtsolis
rbtsolis / index.blade.php
Last active August 10, 2017 15:41
Index View of Students Inveravel
@extends('layouts.master')
@section('title')
Students
@stop
@section('page_header')
Students
@stop
var fs = require('fs'),
path = require('path'),
child_process = require('child_process');
function watchStyles(sourcefile, destinationfolder) {
var Stylus = child_process.spawn('stylus', ['-c','-u', 'nib','-w', sourcefile, '--out', destinationfolder]);
Stylus.stdout.pipe(process.stdout); // notifications: watching, compiled, generated.