Skip to content

Instantly share code, notes, and snippets.

View RodolfoSilva's full-sized avatar
🏠
Working from home

Rodolfo Silva RodolfoSilva

🏠
Working from home
View GitHub Profile
@RodolfoSilva
RodolfoSilva / .gitignore
Created June 6, 2016 11:47 — forked from bergie/.gitignore
Node.js email handling examples
config.json
reading-image.png
@RodolfoSilva
RodolfoSilva / object_create.js
Created April 29, 2016 03:03 — forked from badsyntax/object_create.js
Simple prototypal inheritance in node.js
/* This shows how to use Object.create */
/** BASE MODEL **********************************/
function BaseModel(collection) {
this.collection = collection;
}
BaseModel.prototype.getCollection = function() {
return this.collection;
@RodolfoSilva
RodolfoSilva / custom-error.js
Created April 28, 2016 11:31 — forked from justmoon/custom-error.js
Creating custom Error classes in Node.js
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.extra = extra;
};
require('util').inherits(module.exports, Error);
@RodolfoSilva
RodolfoSilva / validaData.php
Last active March 9, 2016 19:34
Validar data validaData('date', 'format')
<?php
function validaData($date, $format = 'Y-m-d H:i:s')
{
if (!empty($date) && $v_date = date_create_from_format($format, $date)) {
$v_date = date_format($v_date, $format);
return ($v_date && $v_date == $date);
}
return false;
}
@RodolfoSilva
RodolfoSilva / convertData.php
Last active March 9, 2016 19:34
Converter data converteData('format', 'para_formato', 'data', 'timezone')
<?php
function converteData($format, $to_format, $date, $timezone = null)
{
if (!empty($date)) {
$timezone = $timezone ? $timezone : new DateTimeZone(date_default_timezone_get());
$f_date = date_create_from_format($format, $date, $timezone);
return date_format($f_date, $to_format);
}
return false;
}
@RodolfoSilva
RodolfoSilva / GridStream.js
Created March 1, 2016 19:25 — forked from psi-4ward/GridStream.js
NodeJS MongoDB-GridFS Video range stream example Lets your browser seek/jump wihin the video-playback.
var app = require('express')();
var GridStore = require('mongodb').GridStore;
var ObjectID = require('mongodb').ObjectID;
var MongoClient = require('mongodb').MongoClient;
var Server = require('mongodb').Server;
var dbConnection;
MongoClient.connect("mongodb://localhost:27017/ersatz?auto_reconnect", {journal: true}, function(err, db) {
dbConnection = db;
app.listen(3000);
from django.db import models
class Categoria(models.Model):
nome = models.CharField(max_length=200)
slug = models.SlugField(unique=True, blank=True, null=True)
parent = models.ForeignKey('self', blank=True, null=True, related_name='child')
class Produto(models.Model):
from django import forms
from django.contrib import admin
from .models import Categoria
class CategoriaForm(forms.ModelForm):
class Meta:
model = Categoria
fields = '__all__'
def __init__(self, *args, **kwargs):
from django import forms
from django.contrib import admin
from .models import Categoria
class CategoriaForm(forms.ModelForm):
class Meta:
model = Categoria
fields = '__all__'
def __init__(self, *args, **kwargs):
from django import forms
from .models import Categoria
class CategoriaForm(forms.ModelForm):
class Meta:
model = Categoria
fields = '__all__'