Skip to content

Instantly share code, notes, and snippets.

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

Diego Pereira Grassato diegograssato

🏠
Working from home
View GitHub Profile
<?php
namespace Application\View\Helper;
//use Zend\View\Helper\AbstractHelper;
use Zend\Form\View\Helper\AbstractHelper;
use Zend\Form\Form;
class RenderForm extends AbstractHelper {
<?php
namespace Application\Hydrator;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject;
class DateHydrator extends DoctrineObject {
protected function handleTypeConversions($value, $typeOfField) {
if ($typeOfField == 'date') {
angular.module('myApp')
.factory('Traits', function() {
return {
apply: function (_class, _trait) {
_.each(_trait, function (method, name) {
_class.prototype[name] = method;
});
}
}
});
//Grooscript Angular.js TODO example from https://angularjs.org/
//You need next release of grooscript to run it (1.0.1)
class TodoController implements AngularController {
def todos = [
[text:'learn angular', done: true],
[text:'build an angular app', done: false]
]
def addTodo() {
scope.todos << [text: scope.todoText, done: false]
scope.todoText = ''
@diegograssato
diegograssato / gist:b48929fc0c8b1b9f8c05
Created January 25, 2016 00:31 — forked from evandrofalleiros/gist:a7f7e1999527cfd4fe78
Relacionamento 1:N com Mongo Collection no Meteor
Fichas = new Mongo.Collection('fichas');
// Criando coleção Usuarios
Usuarios = new Mongo.Collection('usuarios', {
// Quando uma query é realizada, a coleção Usuarios tranforma o resultado e
// inclui um objeto "fichasObj", que é o conjunto de fichas que pertence
// ao usuário em questão
transform: function(doc) {
// buscar todas as fichas que tem o id do usuário
doc.fichasObj = Fichas.find({
@diegograssato
diegograssato / README.md
Created January 23, 2017 01:44 — forked from tjamps/README.md
Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

The API we are creating in this gist will follow these rules :

  • The API only returns JSON responses
  • All API routes require authentication
  • Authentication is handled via OAuth2 with password Grant Type only (no need for Authorization pages and such).
  • API versioning is managed via a subdomain (e.g. v1.api.example.com)

The API will be written in PHP with the Symfony 2 framework. The following SF2 bundles are used :

It's still a work in progress...

Intro

As William Durand was recently explaining in his SOS, he "didn't see any other interesting blog post about REST with Symfony recently unfortunately". After spending some long hours to implement an API strongly secured with oAuth, I thought it was time for me to purpose my simple explanation of how to do it.

Ok, you know the bundles

You might have already seen some good explanation of how to easily create a REST API with Symfony2. There are famous really good bundles a.k.a. :

@diegograssato
diegograssato / ssh.cs
Created December 21, 2017 23:02 — forked from piccaso/ssh.cs
ssh.net Example - Keybased Authentication, File Upload, Shell Commands
/*
get SSH.NET (BSD License: http://sshnet.codeplex.com/license)
with NuGet:
>Install-Package SSH.NET -Version 2013.4.7
or just get the dll from here: http://j.mp/sshNet
*/
using System;
version: '3'
services:
mongo-express:
image: mongo-express
ports:
- 8081:8081
environment:
ME_CONFIG_BASICAUTH_USERNAME: renatogroffe
ME_CONFIG_BASICAUTH_PASSWORD: MongoExpress2019!
@diegograssato
diegograssato / pf_nat
Created August 4, 2021 15:25 — forked from retspen/pf_nat
Enable NAT on macOS
#!/bin/bash
cat > /usr/local/etc/pf-nat.conf << EOF
nat on en0 from vnic1:network to any -> (en0)
EOF
sudo pfctl -d
sudo sysctl -w net.inet.ip.forwarding=1
sudo pfctl -f /usr/local/etc/pf-nat.conf -e