Skip to content

Instantly share code, notes, and snippets.

View smachs's full-sized avatar
:electron:

Gabriel Correa smachs

:electron:
View GitHub Profile
@sibelius
sibelius / testRequest.ts
Created July 15, 2021 17:53
Test a request using fetch api
import 'isomorphic-fetch';
const run = async () => {
const payload = {
field: 'value'
}
const options = {
method: 'POST',
headers: {
@whoisryosuke
whoisryosuke / gist:5b0d54926c997a6620945d780958ea74
Created September 29, 2018 01:05
Javascript / ES6 - Uppercase first letter of each word (2 ways) -- via: https://stackoverflow.com/a/4878800
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt){
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
// or in ES6:
var text = "foo bar loo zoo moo";
const ucfirst = text => text.toLowerCase()
@dimorphic
dimorphic / react-gmaps-loader.jsx
Created July 27, 2016 08:43
react google maps script loader example
import {
ReactScriptLoader,
ReactScriptLoaderMixin,
} from 'react-script-loader';
export default class UiMap extends React.Component {
constructor(props) {
super(props);
this.state = {
scriptLoading: true,
@kottenator
kottenator / simple-pagination.js
Created July 13, 2015 20:44
Simple pagination algorithm
// Implementation in ES6
function pagination(c, m) {
var current = c,
last = m,
delta = 2,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [],
l;
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@ricardodantas
ricardodantas / validacao+mascara.js
Last active April 30, 2025 12:45
Máscara e validação de RG, CNPJ, CPF, etc...
// JavaScript Document
// adiciona mascara para rg
// Cada estado têm regras e quantidades diferentes de números no registro. Por isso,
// não há uma maneira confiável de fazer a validação do mesmo.
function MascaraRg(v0,errChar='?'){
const v = v0.toUpperCase().replace(/[^\dX]/g,'');
return (v.length==8 || v.length==9)?
v.replace(/^(\d{1,2})(\d{3})(\d{3})([\dX])$/,'$1.$2.$3-$4'):
(errChar+v0)