Skip to content

Instantly share code, notes, and snippets.

@netojoaobatista
netojoaobatista / Date.prototype.diff.js
Created April 26, 2012 20:09
Returns the difference between two Date objects.
Object.defineProperty(Date.prototype,"diff",{
writable: false, configurable: false, enumerable: true,
/**
* Returns the difference between two Date objects.
* @param {Date} The date to compare to.
* @return {Object}
* @throws {TypeError}
*/
value: function(date) {
@leocavalcante
leocavalcante / observer.js
Created June 25, 2012 14:29
javascript observer object
(function ( global, undefined ) {
var observer = {},
topics = {};
observer.on = function ( topic, fn ) {
if ( !topics[topic] ) topics[topic] = [];
topics[topic].push( fn );
return topics[topic].length - 1;
};
observer.trigger = function () {
var args = Array.prototype.slice.call( arguments ),
@leocavalcante
leocavalcante / slugify.js
Created June 25, 2012 15:19
slug strings
(function ( global, undefined ) {
function slugify ( str ) {
return str
.toLowerCase()
.replace( /á|à|â|ã/g, 'a' )
.replace( /é|è|ê/g, 'e' )
.replace( /í|ì|î/g, 'i' )
.replace( /ó|ò|ô|õ/g, 'o' )
.replace( /ú|ù|û/g, 'u' )
.replace( /ç/g , 'c' )
@leocavalcante
leocavalcante / month-name.js
Created June 25, 2012 15:51
returns the name of the given month (pt)
(function ( global, undefined ) {
var months = ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'];
function monthName ( month, short ) {
month = parseInt( month ) - 1;
return short && month !== 4 ? months[month].slice( 0, 3 ) : months[month];
}
global.monthName = global.monthName || monthName;
} ( this ));
@erikhenrique
erikhenrique / bin-cc.md
Last active June 30, 2024 22:14
Bin de cartões de crédito para validação

Validação para cartão de crédito.

Bin e padrões para validação de cartão de crédito.

Bandeira Começa com Máximo de número Máximo de número cvc
Visa 4 13,16 3
Mastercard 5 16 3
@nkt
nkt / Results.md
Last active September 27, 2023 08:24
ReactPHP vs Node.js

wrk -t4 -c400 -d10s http://127.0.0.1:1337/

PHP

Running 10s test @ http://127.0.0.1:1337/
  4 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
 Latency 7.02ms 6.94ms 82.86ms 85.27%
@subfuzion
subfuzion / curl.md
Last active July 18, 2024 17:12
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@sogko
sogko / main.go
Last active May 28, 2024 00:29
Example of creating custom `graphql-go/handler` using `handler.NewRequestOptions()` to parse http.Requests
package main
import (
"encoding/json"
"net/http"
"github.com/graphql-go/graphql"
"github.com/graphql-go/handler"
"github.com/graphql-go/relay/examples/starwars"
)
@bastman
bastman / docker-cleanup-resources.md
Created March 31, 2016 05:55
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@knowbody
knowbody / ex-navigation.md
Last active July 17, 2023 10:14
My exponent's ex-navigation docs/thoughts

Exponent - ex-navigation

This is for now, for my personal use only, things might not be correctly explained here. For the official docs please check: https://github.com/exponentjs/ex-navigation/blob/master/README.md

Navigation bar configuration

On every screen you can use the built-in navigation bar, you can add a title, left button, right button or change navigation bar’s style. All you need to do is pass appropriate params to navigationBar in the route configuration:

import React, { Component } from 'react';