Skip to content

Instantly share code, notes, and snippets.

View tzkmx's full-sized avatar
🎉
estrenando repositorios privados

Jesus Franco tzkmx

🎉
estrenando repositorios privados
View GitHub Profile
@tzkmx
tzkmx / batchcon.bat
Last active May 5, 2016 21:10
Grab TIFFs in this folder and put it in a PDF Bundle, then Open it
@echo off
pushd %1
"C:\Program files\PDFCreator\Images2PDF\Images2PDFC.exe" /i "%1\*.tif" /e "%1\compilado.pdf"
"%1\compilado.pdf
@tzkmx
tzkmx / getFirstIPv4.bat
Last active May 20, 2016 22:30
Loops to get first IPv4 address in CMD && then reset ini file to result
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET _c=0
FOR /F "delims=: tokens=1,2" %%A IN ('ipconfig') DO (
FOR /F "tokens=2" %%C IN ("%%A") DO (
IF !_c! EQU 0 IF /I %%C==IPv4. ( echo %%B & SET /A _c+=1 )
)
)
@tzkmx
tzkmx / grommet_hello_world.html
Created May 31, 2016 23:05 — forked from grommetux/grommet_hello_world.html
Grommet Hello World app
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400italic,400,700' rel='stylesheet' type='text/css'>
<link href='http://grommet.io/assets/latest/css/grommet.min.css' rel='stylesheet' type='text/css'>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.2/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
@tzkmx
tzkmx / ControllerResolver.php
Created June 7, 2016 14:31
Inject services from Pimple Container in Controller arguments
<?php
namespace Controller;
use Silex\ControllerResolver as SilexControllerResolver;
use Symfony\Component\HttpFoundation\Request;
use \Pimple;
/**
* Extension of Silex\ControllerResolver, as that injects Application class if
* its requested by Controller by Typehinting; this looks for, and injects,
* services with same name as parameter argument and validates is the right
@tzkmx
tzkmx / insert-posts.php
Created June 16, 2016 23:53
WordPress: Insert a post into WordPress from an external script
<?php
// Load WordPress
require_once 'path/to/www/wp-load.php';
require_once ABSPATH . '/wp-admin/includes/taxonomy.php';
// Set the timezone so times are calculated correctly
date_default_timezone_set('Europe/London');
// Create post
@tzkmx
tzkmx / iframe_shortcode.php
Created June 23, 2016 22:45
Minimal shortcode to override WordPress virtual ban of iframes
<?php
function iframe_render_shortcode($atts) {
$keys = array_flip(array_keys($atts));
$params = shortcode_atts($keys, $atts);
$out = [];
foreach($params as $key => $val) {
$out[] = $key . '="' . $val . '"';
}
return '<iframe ' . implode(' ', $out) . '></iframe>';
}
@tzkmx
tzkmx / ThemeClass.php
Created July 25, 2016 18:06
Towards a more testable WordPress. The main idea is simple. Instead of piling everything into a theme's functions.php file, create a class to hold all the theme's functions. Then, using dependency injection, add the WordPress facade and inside the ThemeClass make all calls to the facade instead of the global WP functions. This allow us to use Mo…
<?php
/**
* This is a straightforward example of what a ThemeClass may look like. It contains all the
* expected initialization, and wp_enqueue_script calls.
*/
class ThemeClass
{
protected $wp;
protected $themeDirectory;
@tzkmx
tzkmx / demo.js
Created August 5, 2016 19:33
Demo of tail call optimization in javascript with metaret.js
function fact(i) {
return i === 1 ? 1 : i * fact(i-1);
}
console.time('fact recursive naive');
for(var i = 0; i<1000000 ; i++) {
var g=fact(170);
}
console.log(g);
console.timeEnd('fact recursive naive');
metaparse("metafun fact_m(self, i, acc) { " +
@tzkmx
tzkmx / counter-redux-example.js
Last active August 15, 2016 01:22
React-Redux standalone in browser (no browserify, no webpack, just plain <script> tags)
// React component
var Counter = React.createClass( {
render: function() {
var value = this.props.value;
var onIncreaseClick = this.props.onIncreaseClick;
return (
React.createElement("div", null,
React.createElement("span", null, value),
React.createElement("button", {onClick: onIncreaseClick}, "Increase")
)
@tzkmx
tzkmx / 1fix-switch-theme-on-certain-pages.php
Created September 28, 2016 01:14 — forked from yoren/1fix-switch-theme-on-certain-pages.php
WordPress tiny plugin - Switch theme on certain pages
<?php
/**
* @package One_Fix_Switch_Theme
* @version 1.0
*/
/*
Plugin Name: One Fix Switch Theme
Plugin URI: https://www.1fix.io
Description: Switch theme on certain pages.
Author: Yoren Chang