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
@diegograssato
diegograssato / gist:a72f3f48d328da960f19051f5daae6c1
Created April 9, 2024 13:26 — forked from ibnux/gist:59dd7d64bd9cb7e1e670b6ddd70ad991
Mikrotik Script for DHCP Lease to Queue simple
:local queueName "Client-$leaseActMAC";
:local ipAdd "$leaseActIP/32";
:if ([:len [/queue simple find name=$queueName]] = 0) do={
:log info "No Queue";
/queue simple add name=$queueName target=($ipAdd) limit-at=10M/4M max-limit=10M/4M comment=[/ip dhcp-server lease get [find where active-mac-address=$leaseActMAC && active-address=$leaseActIP] host-name];
} else={
:log info "exists";
:local ada [/queue simple get [find name=$queueName] target];
{
"id": "45c0996e-ac5e-4271-80e1-a09a16391a27",
"name": "Sonoff Mini",
"values": [
{
"key": "sonoff_ip",
"value": "10.0.1.32",
"enabled": true
},
{
@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
version: '3'
services:
mongo-express:
image: mongo-express
ports:
- 8081:8081
environment:
ME_CONFIG_BASICAUTH_USERNAME: renatogroffe
ME_CONFIG_BASICAUTH_PASSWORD: MongoExpress2019!
@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;

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 / 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 :

@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({
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 = ''