Skip to content

Instantly share code, notes, and snippets.

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

Leonardo Vidal lvidal1

🏠
Working from home
View GitHub Profile
@lvidal1
lvidal1 / sql
Created October 31, 2016 18:17
Make a slug in PostgreSQL
-- From http://scottbarnham.com/blog/2010/12/20/make-a-slug-in-postgresql-translating-diacritics/
CREATE OR REPLACE FUNCTION getslug(texte varchar) RETURNS VARCHAR AS
$$
DECLARE
result varchar;
BEGIN
-- Add formtat to special case
result := replace(texte , 'æ', 'ae');
result := replace(result , 'œ', 'oe');
@lvidal1
lvidal1 / friendly-filename.php
Created December 20, 2016 18:08
Make filename friendly (slug it) recursively by giving a path directory.
<?php
// Usage:
// 1. Open console
// 2. Go to desired folder and run the script by:
// $ php friendly-filename.php
// Optional: You can pass the desired folder by argument:
// $ php friendly-filename.php /desired/folder/I/want/to/make/it/friendly
@lvidal1
lvidal1 / server.js
Last active December 30, 2016 21:17
Setup a basic node-server
/* Previous Considerations
* ------------------------------- */
//a. It is necessary nodejs must be installed on pc/linux or mac.
//b. This server runs on 127.0.0.1:8081. You can access :
// - by console with '$ node main.js'
// - by browser by goint to http://127.0.0.1:8081/
/* The very basic server
* -------------------------------*/
// 1. Import required modules
@lvidal1
lvidal1 / app.js
Created January 13, 2017 18:18
Angular - Check if template exist on $routeProvider
$routeProvider.when("/resource/:slug", {
controller: "ResourceController",
resolve: {
check: ["$route", "$http", "$location", function($route, $http, $location){
return $http.get("/views/" + $route.current.params.slug + ".html").success(function(res){
return true;
}).error(function(res){
return $location.path("/");
});
}]
@lvidal1
lvidal1 / server.graphql.ts
Created June 8, 2017 06:38
Very "Hello-world" for graphql server - Credit Udemy:GraphQL for Absolute Beginners: The Newbie Guide
var {graphql, buildSchema} = require('graphql');
var schema = buildSchema (`
type Query{
hello : String
}
`);
var root = {
hello: () => {
return 'Hello World.';
@lvidal1
lvidal1 / rx-debounce-typing.ts
Created July 3, 2017 05:44
Debounce on typing with Rxjs
var input = document.querySelector('input');
var observable = Rx.Observable.fromEvent(input,'input');
observable
.map(e => e.target.value)
.filter((v)=> v.length > 0)
.debounceTime(500)
.distinctUntilChanged()
.subscribe({
next: function(e){
@lvidal1
lvidal1 / rx-debounce-typing.ts
Created July 3, 2017 05:54
Debounce on typing with Rxjs (pluck operator)
var input = document.querySelector('input');
var observable = Rx.Observable.fromEvent(input,'input');
observable
.pluck('target','value') // nested attributes from event
.filter((v)=> v.length > 0)
.debounceTime(500)
.distinctUntilChanged()
.subscribe({
next: function(e){
@lvidal1
lvidal1 / apollo.auth-header.ts
Created July 18, 2017 20:19
Apollo middleware with Authorization header
networkInterface.use([{
applyMiddleware(req, next) {
let authToken = localStorage.getItem("authToken");
if (authToken) {
req.options.headers = Object.assign({},req.options.headers, {
authorization: `Bearer ${authToken}`
});
}
next();
}
@lvidal1
lvidal1 / rtl8723BE-setup.txt
Created August 1, 2017 02:29
Realtek RTL8723BE weak wifi signal and disconnects
1. Open Terminal, and then
iwconfig
and note down the wl* number.
2. Download new driver. Download rock.new_btcoex from GIT and unzip it to the desktop for example.
3. Again in Terminal type and run:
cd Desktop/rtlwifi_new-rock.new_btcoex
make
sudo make install type your ubuntu password.
sudo modprobe -rv rtl8723be
sudo modprobe -v rtl8723be ant_sel=2
@lvidal1
lvidal1 / server.conf
Created March 5, 2018 21:39
Nginx configuration file using php7.1
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.