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 / 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.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 / 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 / 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');