Skip to content

Instantly share code, notes, and snippets.

View sirtimid's full-sized avatar

Dimitris Marlagkoutsos sirtimid

View GitHub Profile
@sirtimid
sirtimid / simple-node-server.js
Last active January 27, 2017 18:49
A simple node http server that logs all requests
'use strict'
const http = require('http')
const port = 3000
http
.createServer((request, response) => {
// Set CORS headers
response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Access-Control-Request-Method', '*');
@sirtimid
sirtimid / auto-polylang-media.php
Last active April 10, 2021 17:16
Translate media automatically when using Polylang in Wordpress
<?php
if ( !function_exists( 'translate_all_media' ) ) {
function translate_all_media() {
global $polylang;
if(!$polylang) return;
// find languages
$langs = array();
@sirtimid
sirtimid / get_url_by_template.php
Last active November 16, 2016 22:49
Get a wordpress page URL by template name
<?php
if(!function_exists('get_url_by_template')){
function get_url_by_template($tmpl){
$pages = query_posts(array(
'post_type' =>'page',
'meta_key' =>'_wp_page_template',
'meta_value'=> $tmpl
));
@sirtimid
sirtimid / wp_cleanup.php
Last active March 14, 2017 09:48
Cleanup wordpress of unwanted dashboard widgets and injected styles
<?php
// filter to remove TinyMCE emojis
if ( !function_exists( 'disable_emojicons_tinymce' ) ) {
function disable_emojicons_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
@sirtimid
sirtimid / fade.js
Created November 1, 2016 16:42
Fade in/out an element with vanilla javascript
/**
* Fade in/out an element
* Note: I am not using requestAnimationFrame as it does not play well in mobile browsers
*
* @param {Object} [options={}] An object with options.
* @param {Element} [options.el] The Element object.
* @param {String} [options.type='in'] The fade type: 'in' or 'out'.
* @param {Integer} [options.duration=400] The duration of the animation in miliseconds.
* @param {String} [options.display='block'] The display property of the element when fade in starts.
* @param {Boolean} [options.empty=false] Set to true if you need to empty the element after fade out.
@sirtimid
sirtimid / detonify.js
Created November 8, 2016 23:45
Detonify a string in Javascript
String.prototype.detonify = function () {
'use strict';
// set string of characters with tones
let tones = 'ΆάΈέΉήΌόΎύΏώΊΪϊίΫϋ'.split('')
// set the equivalent string of characters without tones
let detones = 'ΑαΕεΗηΟοΥυΩωΙΙιιΥυ'.split('')
let str = this.toString()
for (let key in tones) {
let regex = new RegExp(tones[key], 'g')
str = str.replace(regex, detones[key] || tones[key])
@sirtimid
sirtimid / template-skroutz.php
Last active November 16, 2016 22:56
Wordpress WooCommerce Skroutz XML feed generator
<?php
/*
*Template Name: Skroutz XML
*/
/*
* This Wordpress template generates a xml feed for skroutz.gr
*/
header ("Content-Type:text/xml");
@sirtimid
sirtimid / um_vies_vat_validation.php
Last active October 3, 2022 21:32
VIES VAT custom validation for Wordpress Ultimate Members field
<?php
/**
* This is a custom validation for Ultimate Members Wordpress plugin
* Apply custom validation to VAT field with the name vat_number
* It requires also a country field
* This expects a user to enter a VAT Number in the following format:
* EL-123456789
*
* Add um_custom_vat_validation on Custom Action field