Skip to content

Instantly share code, notes, and snippets.

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

Eduardo Domene Junior Edudjr

🏠
Working from home
  • Mercado Livre
  • Sao Paulo
View GitHub Profile
@Edudjr
Edudjr / multiparty-index.js
Created May 3, 2018 16:42
Multiparty with support for file names
/* Replace your multiparty/index.js inside node_modules with the code below.
* Example:
* var EXT_RE = /(\.[_\-a-zA-Z0-9]{0,16}).* /; <- remove space
* var options = {
* filename: function(filename, callback){
* var name = filename.replace(EXT_RE, "");
* callback(name+'-YEAH-'+1234+'.png');
* }
* }
* // if using multiparty
@Edudjr
Edudjr / example1.json
Created October 16, 2018 20:56
Example Json for API
{
"userId": 47,
"userName": "Agente 47",
"age": 27,
"address": {
"streetNumber": "3000",
"streetName": "Wellington Square Street"
}
}
router.get('/:id', function(req, res) {
var id = req.params.id;
var json = {
userId: id,
userName: "Agente "+id,
age: 27,
address: {
streetNumber: "3000",
streetName: "Wellington Square Street"
}
/* arquivo: routes/index.js
* url de resposta: http://localhost:3000/respondeaqui
*/
router.get('/respondeaqui', function(req, res, next) {
res.send('ok');
});
/* arquivo: routes/users.js
* url de resposta: http://localhost:3000/users/aquiagora
*/
router.get('/aquiagora', function(req, res, next) {
res.send('ok');
});
var routes = require('./routes/index'); //#1
var users = require('./routes/users'); //#2
...
app.use('/', routes); //#3
app.use('/users', users); //#4
@Edudjr
Edudjr / run-sonar-swift.sh
Last active July 11, 2019 19:34
Script used for running Swift projects in Sonarqube. There is just a small change to the original: includedCommandLineFlags=" --include .*/${currentDirectory}/${word}/*"
#!/bin/bash
#
# backelite-sonar-swift-plugin - Enables analysis of Swift and Objective-C projects into SonarQube.
# Copyright © 2015 Backelite (${email})
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
@Edudjr
Edudjr / sonar-project.properties
Created November 12, 2018 20:23
Properties file for running Swift projects in Sonarqube. It needs the open source sonar-swift plugin.
#
# Swift SonarQube Plugin - Enables analysis of Swift and Objective-C projects into SonarQube.
# Copyright © 2015 Backelite (${email})
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@Edudjr
Edudjr / Currying.swift
Last active June 6, 2019 22:37
This is a currying example for Swift 4.2
func sum(v1: Int, v2: Int) -> Int {
return v1 + v2
}
func sub(v1: Int, v2: Int) -> Int {
return v1 - v2
}
func operation (_ operation: @escaping (Int, Int) -> Int) -> (Int, Int) -> Int {
return { v1, v2 in
@Edudjr
Edudjr / Drink.swift
Created August 9, 2019 11:27
Codable/Decodable example for parsing JSON with optional parameters
class Drink: Codable {
var name: String
var color: String?
private enum CodingKeys: String, CodingKey {
case name, color
}
required init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)