Skip to content

Instantly share code, notes, and snippets.

View icavalheiro's full-sized avatar
😅

Ivan Schuaste Cavalheiro icavalheiro

😅
View GitHub Profile
@icavalheiro
icavalheiro / delete_trash.csx
Last active March 20, 2019 17:27
CSX script to delete all files that follow a pattern from the current directory
#!/usr/bin/env dotnet-script
/*
You will need dotnet core and "dotnet tool install -g dotnet-script"
*/
using System;
using System.IO;
var files = Directory.GetFiles("./", "._*", SearchOption.AllDirectories);
@icavalheiro
icavalheiro / 404.js
Last active April 18, 2019 19:44
404 mapper for spa application that need to reroute all 404 requests to the main page in Strapi CMS
'use strict';
let fs = require('fs');
let path = require('path');
const pathToIndexFile = 'public/index.html';
module.exports = async ctx => {
let indexPath = path.resolve(pathToIndexFile);
ctx.status = 200;
@icavalheiro
icavalheiro / gulpfile.js
Last active July 8, 2019 22:26
Gulp file with watch and build that use parcel as the bundler (WEB)
const gulp = require('gulp');
const notifier = require('node-notifier');
const parcel = require('parcel-bundler');
const shell = require('shelljs');
function notifyError(err) {
notifier.notify({
title: 'Gulp detect an error',
message: 'Something broke! Please check console for logs!'
});
const Hapi = require('@hapi/hapi')
const index = require('./endpoints/index')
const teste = require('./endpoints/teste')
let server = Hapi.server({
port: 3000,
host: 'localhost'
})
let port = 3000;
@icavalheiro
icavalheiro / read_perm_pgsql.sql
Last active August 28, 2019 15:00
Grant read permissions to user Postgres
GRANT CONNECT
ON DATABASE database_name
TO user_name;
GRANT SELECT /*, INSERT, UPDATE, DELETE */
ON ALL TABLES IN SCHEMA public
TO user_name;
@icavalheiro
icavalheiro / scaffold_db_dotnet.sh
Created August 7, 2019 21:26
Scaffold database with ef core
# dotnet add package MySql.Data.EntityFrameworkCore
# dotnet add package Microsoft.EntityFrameworkCore.Design
# dotnet tool install --global dotnet-ef --version 3.0.0-*
dotnet ef dbcontext scaffold "server=localhost;port=3306;user=root;password=mypass;database=databasename" MySql.Data.EntityFrameworkCore -o Database -f
@icavalheiro
icavalheiro / Customization.cs
Created August 26, 2019 21:22
Umbraco 8 customization file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Umbraco.Core.Composing;
using Umbraco.Web;
using Umbraco.Web.Dashboards;
using Umbraco.Web.Sections;
namespace YOUR_PROJECT_NAME
@icavalheiro
icavalheiro / JsonController.cs
Last active August 8, 2021 04:01
Umbraco Json controller based on the ContentType renderer. Use this to return the content as a json instead of a view (great for headless mode)
using Newtonsoft.Json;
using System;
using System.Net;
using System.Web;
using System.Web.Mvc;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
@icavalheiro
icavalheiro / SearchController.cs
Last active September 27, 2019 18:54
Umbraco search controller based on contenttype controllers. Returns json's as responses.
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Mvc;
namespace YOUR_APP_NAME.Controllers
{
@icavalheiro
icavalheiro / scrollDetector.js
Created October 1, 2019 23:13
detects vertical scroll movement on a page/element, works on mobile and desktop
function getTouch(event) {
if (event.touches) return event.touches[0]
return event;
}
function addSwipeListener(element, callback, startCallback, finishCallback) {
let y;
let handleTouchStart = (event) => {
y = getTouch(event).clientY;