Skip to content

Instantly share code, notes, and snippets.

View LSViana's full-sized avatar
📱
Web and Mobile

Lucas Viana LSViana

📱
Web and Mobile
View GitHub Profile
@LSViana
LSViana / NHAppender.cs
Last active July 26, 2021 14:58
log4net appender to format NHibernate queries replacing parameters by their actual values
using System.Text;
using System.Text.RegularExpressions;
using log4net.Appender;
using log4net.Core;
namespace RecruitmentTesting.Business.Repositories
{
public class NHAppender : ForwardingAppender
{
protected override void Append(LoggingEvent loggingEvent)
^((?!text).)*$
// Vue.js configuration
/*
1. Create file vue.config.js and export 'publicPath' with the value of '/sub/path' with the syntax of module.exports = { ... }
2. Set the router 'base' property to the same value '/sub/path' used in vue.config.js
Obs.: The value of '/sub/path' MUST start with a '/' to avoid it being interpreted as a relative path
*/
// Express.js server
const express = require('express')
@LSViana
LSViana / wsc-hide-login-plugin.php
Last active March 9, 2020 01:40
Change /wp-admin and hide /wp-login.php
function wsc_hide_login($headers) {
$url = $_SERVER["REQUEST_URI"];
if(strpos($url, "/wp-admin") !== false || strpos($url, "/wp-login.php") !== false) {
$method = $_SERVER["REQUEST_METHOD"];
if($method !== "GET") return;
$user = wp_get_current_user();
$isAdmin = sizeof(array_filter($user->roles, function($item) {
return $item === "administrator";
})) > 0;
if(!$isAdmin) {
@LSViana
LSViana / temperature-bar.php
Created January 30, 2020 22:38
Drawing gradients using GD library through PHP
<?php
$temperature = $_REQUEST['temperature'] ?? 0;
if($temperature < 0 || $temperature > 100) {
$temperature = min(100, max(0, $temperature));
}
// Business functions
function lerpInt($min = 0, $max = 1, $progress = 0) {
return (($max - $min) * $progress) + $min;
}
// Parameters
<?php
$method = $_SERVER['REQUEST_METHOD'];
$uploadedFile = false;
if($method == 'POST') {
$totalFiles = count($_FILES['file']['name']);
for ($i = 0; $i < $totalFiles; $i++) {
$fileData = $_FILES['file'];
$fileInfo = pathinfo($fileData['name'][$i]);
$currentUploadPath = wp_upload_dir();
$uploadPath = $currentUploadPath['path'];
@LSViana
LSViana / web.config
Created August 14, 2019 19:07
Redirecting requests to "/" if not API on IIS
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
@LSViana
LSViana / launch.json
Last active October 2, 2019 16:41
Debug Vue.js in Chrome using VS Code
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "vuejs: chrome",
@LSViana
LSViana / AddInMemoryDb.cs
Last active July 27, 2019 01:10
ASP.NET Core Mock API Boilerplate
services.AddDbContext<Db>(x => x.UseInMemoryDatabase("Db"));
@LSViana
LSViana / change-resolution.sh
Created December 18, 2018 18:15
Change screen DPI in Ubuntu using GNOME
gsettings set org.gnome.desktop.interface text-scaling-factor 0.9375