Skip to content

Instantly share code, notes, and snippets.

View JohnProg's full-sized avatar
🎯
Focusing

John Paul JohnProg

🎯
Focusing
  • Lima, Perú
View GitHub Profile
def age(self):
if hasattr(self, "_age"):
return self._age
today = datetime.date.today()
age = today.year - self.birthdate.year
if today < datetime.date(today.year, self.birthdate.month, self.birthdate.day):
age -= 1
# coding: utf-8
import jwt
from datetime import datetime
from flask import Flask, jsonify, request
app = Flask(__name__)
key = 'foo'
@app.before_request
@JohnProg
JohnProg / multiple-3rd-party-widgets.js
Created April 30, 2016 02:18 — forked from zenorocha/multiple-3rd-party-widgets.js
Loading multiple 3rd party widgets asynchronously
(function() {
var script,
scripts = document.getElementsByTagName('script')[0];
function load(url) {
script = document.createElement('script');
script.async = true;
script.src = url;
scripts.parentNode.insertBefore(script, scripts);
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
setuid ubuntu
chdir /opt/myAplicacion
env PORT=3000
@JohnProg
JohnProg / factory.js
Created March 23, 2016 16:11
Fake responses in unit tests JS
var app = angular.module('App', []);
app.factory('Song', function($http, $q) {
function Song() {}
Song.getAverageSongPrice = function(artist) {
var dfd = $q.defer();
$http.get('http://localhost:4000/artists/eminem/songs').then(function(resp) {
var total = 0;
describe('TestController', function () {
var controller = null;
$scope = null;
beforeEach(function () {
module('myApp');
});
beforeEach(inject(function ($controller, $rootScope) {
@JohnProg
JohnProg / server.js
Created March 23, 2016 14:15
basic server expressJS
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/public'));
var host = process.env.IP || '0.0.0.0',
port = process.env.PORT || 3000;
var server = app.listen(port, host, function() {
console.log('Listening at http://%s:%s', host, port);
vagrant init
vagrant box add mi_caja_ubuntu_precise_32 http://files.vagrantup.com/precise32.box
vagrant ssh // Access to the
vagrant suspend // Move from RAM to disk
vagrant resume // Retake virtual machine
vagrant halt // Stop virtual machine
vagrant destroy // Destroy virtual machine
vagrant status // See current status of the virtual machine
/**
* Created by gaspar on 22/sept/15.
*/
//angularJS
(function () {
var app = angular.module('app',
//ejemplo de algun controlador
['app.mainController']
);
/**
* Este script de javascript permite trabajar transparentemente solicitudes que requieren
* protección del token CSRF por medio de AJAX JQUERY.
* Esto te permitirá hacer solcitudes a web Services de Django por medio de AJAX Jquery.
* Para utilizarlo basta con integrar el archivo DjangoAjax.js en tu directorio de JS y hacer referencia a él en tus templates
* que requieren del uso de AJAX por POST o algún otro que requiera el token CSRF.
* Este script está basado en la documentación oficial de Django https://docs.djangoproject.com
*/
$(function(){