Skip to content

Instantly share code, notes, and snippets.

View digitalhydra's full-sized avatar
💭
please don't turn this into The MS social network

Jairo Mejia digitalhydra

💭
please don't turn this into The MS social network
View GitHub Profile
@digitalhydra
digitalhydra / example-wp-list-table.php
Created August 8, 2016 03:15 — forked from paulund/example-wp-list-table.php
An example code of using the WP_List_Table class. With Pagination.
<?php
/*
* Plugin Name: Paulund WP List Table Example
* Description: An example of how to use the WP_List_Table class to display data in your WordPress Admin area
* Plugin URI: http://www.paulund.co.uk
* Author: Paul Underwood
* Author URI: http://www.paulund.co.uk
* Version: 1.0
* License: GPL2
*/
@digitalhydra
digitalhydra / gravatar.php
Created January 19, 2016 15:19
check if avatar/gravatar is valid(exists)
function validate_gravatar($email) {
// From http://codex.wordpress.org/Using_Gravatars
// Craft a potential url and test its headers
$hash = md5($email);
$uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=404';
$headers = @get_headers($uri);
if (!preg_match("|200|", $headers[0])) {
$has_valid_avatar = FALSE;
} else {
$has_valid_avatar = TRUE;
@digitalhydra
digitalhydra / functions.php
Created January 18, 2016 16:07
How to not redirect to wp-login.php if login fails?
/*-------------------------------------------------------------------------------------*/
/* Login Hooks and Filters
/*-------------------------------------------------------------------------------------*/
if( ! function_exists( 'custom_login_fail' ) ) {
function custom_login_fail( $username ) {
$referrer = $_SERVER['HTTP_REFERER']; // where did the post submission come from?
// if there's a valid referrer, and it's not the default log-in screen
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
if ( !strstr($referrer,'?login=failed') ) { // make sure we don’t append twice
wp_redirect( $referrer . '?login=failed' ); // append some information (login=failed) to the URL for the theme to use
var uuids = angular.module('uuids', []);
uuids.factory("rfc4122", function () {
return {
newuuid: function () {
// http://www.ietf.org/rfc/rfc4122.txt
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
@digitalhydra
digitalhydra / hexagon.scss
Created April 14, 2015 12:48
css hexagon
.hex:before {
content: " ";
width: 0; height: 0;
border-bottom: 30px solid #6C6;
border-left: 52px solid transparent;
border-right: 52px solid transparent;
position: absolute;
top: -30px;
}
@digitalhydra
digitalhydra / introrx.md
Last active August 29, 2015 14:18 — forked from staltz/introrx.md

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

/*global angular: true, google: true, _ : true */
'use strict';
angular.module('geocoder', ['ngStorage']).factory('Geocoder', function ($localStorage, $q, $timeout) {
var locations = $localStorage.locations ? JSON.parse($localStorage.locations) : {};
var queue = [];
// Amount of time (in milliseconds) to pause between each trip to the
@digitalhydra
digitalhydra / restorecart.php
Created January 28, 2014 16:43
restore cart
/**
1264 * Cancel the order and restore the cart (before payment)
1265 *
1266 * @access public
1267 * @param string $note (default: '') Optional note to add
1268 * @return void
1269 */
1270 public function cancel_order( $note = '' ) {
1271 global $woocommerce;
1272
@digitalhydra
digitalhydra / backbutton.php
Created December 14, 2013 14:13
crear link a pagina anterior en wordpress
<?php wp_get_referer() ?>
@digitalhydra
digitalhydra / alphaidgenerator.php
Created December 13, 2013 22:09
alpha id generator
<?php
/**
* Translates a number to a short alhanumeric version
*
* Translated any number up to 9007199254740992
* to a shorter version in letters e.g.:
* 9007199254740989 --> PpQXn7COf
*
* specifiying the second argument true, it will
* translate back e.g.: