Skip to content

Instantly share code, notes, and snippets.

View leandroh's full-sized avatar
:shipit:
To deploy or not to deploy?

Leandro Pará leandroh

:shipit:
To deploy or not to deploy?
View GitHub Profile
@leandroh
leandroh / string.rb
Created November 10, 2016 18:50
Strips all HTML tags in Ruby
class String
def strip_tags
self.gsub(/<\/?[^>]*>/, '') if self
end
end
@leandroh
leandroh / factorial.js
Created July 4, 2016 20:40
Test recursive factorial function in JavaScript.
const assert = require('assert');
function factorial(n) {
if (n > 1) {
return n * factorial(n - 1);
}
return 1;
}
assert.equal(factorial(1), 1);
@leandroh
leandroh / clear_bash_history.sh
Created June 21, 2016 20:14
You can clear your bash history
cat /dev/null > ~/.bash_history && history -c && exit
@leandroh
leandroh / places.js
Created May 10, 2016 02:58
Nearby Search Requests
'use strict';
var request = require('request');
var lat = -26.228889;
var lon = -52.670833;
var keyword = 'Pizzaria';
var output = 'json';
var radius = 2000;
var key = 'AIzaSyDVuLEXpSrOyB71IAS152xs7ACp-_HFCdw';
@leandroh
leandroh / rollback_push_git.sh
Created April 22, 2016 19:39
Reset the staging area and the working directory to overwrite all changes in the working directory, too. So make sure you really want to throw away your local developments before using it.
git reset --hard <commit_hash>
git push --force
@leandroh
leandroh / app.js
Created March 28, 2016 16:23
Angular app main module
angular
.module('app', [])
.controller('miCtrl', miCtrl);
function miCtrl ($scope) {
$scope.mensaje = "Mensaje desde el Controlador";
}
@leandroh
leandroh / ng-app.html
Last active March 28, 2016 16:22
Angular controller
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AngularJS</title>
</head>
<body ng-app="app">
<div class="container" ng-controller="miCtrl">
<h1>{{mensaje}}</h1>
</div>
@leandroh
leandroh / fetch_api.js
Last active March 26, 2016 00:37
Fetch API basic concepts
// url (obrigatório), options (opcional)
fetch('/api/url', {
method: 'get'
}).then(function(response) {
// Sucesso :)
}).catch(function(err) {
// Erro :(
});
@leandroh
leandroh / ajax.js
Created March 24, 2016 19:47
XHR is a mess!
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
request = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (e) {
try {
request = new ActiveXObject('Microsoft.XMLHTTP');
}
{
"short_name": "Pokedex.org",
"name": "Pokedex.org",
"display": "standalone",
"icons": [
{
"src": "img/icon-48.png",
"sizes": "48x48",
"type": "image/png"
},