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)
{
@dtipson
dtipson / responsive-request-desktop-site.js
Last active February 21, 2025 16:00
How to make responsive sites better respect the "Request a desktop site" feature on modern mobile browsers.
/*
Enable the "Request Desktop Site" functions on mobile chrome (android and iOS) allow users to see desktop layouts on responsive sites. Note that this is distinct from "opt out of mobile!" buttons built into your site: this is meant to work with the browser's native opt-in/opt-out functionality.
Since these functions work, in part, by simply spoofing the user agent to pretend to be desktop browsers, all we have to do is just remember that the browser once claimed to be android earlier in the same session and then alter the viewport tag in response to its fib.
Here's an example viewport tag <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> that we'd be setting to scaleable-yes,max scale=2. That's just an example of something that works on the site I was building: you should customize the "desktop" viewport content setting to whatever works for your site's needs. If you wanted, you could stick this code in the head just after the primary viewport tag so that the br
@adamstac
adamstac / gist:7462202
Last active March 27, 2025 11:27
Install and configure Sendmail on Ubuntu

Install and configure Sendmail on Ubuntu

This should help you get Sendmail installed with basic configuration on Ubuntu.

  1. If sendmail isn't installed, install it: sudo apt-get install sendmail
  2. Configure /etc/hosts file: nano /etc/hosts
  3. Make sure the line looks like this: 127.0.0.1 localhost yourhostname
  4. Run Sendmail's config and answer 'Y' to everything: sudo sendmailconfig
  5. Restart apache sudo service apache2 restart
@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';
}
@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;