Skip to content

Instantly share code, notes, and snippets.

View jrobinsonc's full-sized avatar
🎯
Focusing

Jose Robinson jrobinsonc

🎯
Focusing
View GitHub Profile
@jrobinsonc
jrobinsonc / number-format.js
Last active July 23, 2021 22:09
Funcion para darle formato a un número. #javascript #numbers
function number_format(amount, decimals) {
amount += ''; // por si pasan un numero en vez de un string
amount = parseFloat(amount.replace(/[^0-9\.]/g, '')); // elimino cualquier cosa que no sea numero o punto
decimals = decimals || 0; // por si la variable no fue fue pasada
// si no es un numero o es igual a cero retorno el mismo cero
if (isNaN(amount) || amount === 0)
return parseFloat(0).toFixed(decimals);
@jrobinsonc
jrobinsonc / README.md
Last active May 3, 2018 20:20
Cut/truncate text to specific length. #php #strings

Cut text to specific length

Use this function to cutting text to a specific length, with the ability to prevent that the last word be cutted in half.

Usage

require 'cutText.php';

$text1 = 'Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut laboredo.';
@jrobinsonc
jrobinsonc / regenerate-thumbnails.php
Created August 27, 2013 08:35
Regenerate thumbnails in WordPress.
<?php
function regenerateThumbnails()
{
global $wpdb;
$images = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%'");
foreach ($images as $image)
{
@jrobinsonc
jrobinsonc / time_elapsed_string.php
Created February 16, 2014 17:35
time elapsed string
<?php
function time_elapsed_string($ptime)
{
$etime = time() - $ptime;
if ($etime < 1)
{
return '0 seconds';
}
{"1":{"Pais":"Republica Dominicana","Provincia":{"1":{"Nombre":"Distrito Nacional","Capital":"Santo Domingo de Guzmán"},"2":{"Nombre":"Azua","Capital":"Azua de Compostela","Municipio":{"1":{"Nombre":"Azua de Compostela","Distrito":{"1":"Barreras ","2":"Barro Arriba ","3":"Clavellina ","4":"Emma Balaguer Viuda Vallejo ","5":"Las Barías-La Estancia ","6":"Las Lomas ","7":"Los Jovillos ","8":"Puerto Viejo"}},"2":{"Nombre":"Estebanía"},"3":{"Nombre":"Guayabal"},"4":{"Nombre":"Las Charcas","Distrito":{"9":"Hatillo ","10":"Palmar de Ocoa"}},"5":{"Nombre":"Las Yayas de Viajama","Distrito":{"11":"Villarpando ","12":"Hato Nuevo-Cortés"}},"6":{"Nombre":"Padre Las Casas","Distrito":{"13":"La Siembra ","14":"Las Lagunas ","15":"Los Fríos"}},"7":{"Nombre":"Peralta"},"8":{"Nombre":"Pueblo Viejo","Distrito":{"16":"El Rosario"}},"9":{"Nombre":"Sabana Yegua","Distrito":{"17":"Proyecto 4 ","18":"Ganadero ","19":"Proyecto 2-C"}},"10":{"Nombre":"Tábara Arriba","Distrito":{"20":"Amiama Gómez ","21":"Los Toros ","22":"Tábara Abajo
@jrobinsonc
jrobinsonc / contact-form.html
Last active August 29, 2015 13:58
Formulario de contacto
<!doctype html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>Formulario de contacto</title>
<link rel="stylesheet" type="text/css" href="styles.css">
@jrobinsonc
jrobinsonc / README.md
Last active January 23, 2018 16:00
Share JS
@jrobinsonc
jrobinsonc / tweets.php
Created May 9, 2014 20:40
Get tweets from Twitter API v1.1
<?php
function get_twitter_access_token($consumer_key, $consumer_secret)
{
$options = array(
CURLOPT_POSTFIELDS => array('grant_type' => 'client_credentials'),
CURLOPT_HTTPHEADER => array('Authorization: Basic ' . base64_encode($consumer_key . ':' . $consumer_secret)),
CURLOPT_HEADER => FALSE,
CURLOPT_URL => 'https://api.twitter.com/oauth2/token',
CURLOPT_RETURNTRANSFER => TRUE
@jrobinsonc
jrobinsonc / linkify.php
Last active August 29, 2015 14:01
Linkify
<?php
/**
* linkify
*
* @link Github: https://gist.github.com/jrobinsonc/e79578c41ca48bac9bde
* @param string $value
* @param array $protocols
* @param array $attributes
* @param string $mode
@jrobinsonc
jrobinsonc / example.php
Last active August 29, 2015 14:04
Wordpress filter: image_downsize
<?php
/**
* Default:
*/
$post_thumbnail_id = get_post_thumbnail_id(get_the_ID());
$width = 640;
$height = 480;