Skip to content

Instantly share code, notes, and snippets.

View mitogh's full-sized avatar
:octocat:
I may be slow to respond.

Crisoforo Gaspar Hernández mitogh

:octocat:
I may be slow to respond.
View GitHub Profile
@mitogh
mitogh / changeFormatScreenshot.sh
Created September 19, 2014 15:51
Change format of the screenshots in Mac.
defaults write com.apple.screencapture type png
killall SystemUIServer
# Different formats
# png: Portable Network Graphic
# pdf: Portable Document Format
# jpg: Joint Photographic Experts Group (JPEG)
# tif: Tagged Image File Format (TIFF)
# gif: Graphics Interchange Format
# pct: Macintosh QuickDraw Picture (PICT)
@mitogh
mitogh / changeLocationScreenshots.sh
Created September 19, 2014 15:53
Change default location for the screenshots in Mac
defaults write com.apple.screencapture location ~/Pictures
killall SystemUIServer
# Where ~/Pictures is the current location where the screenshots
# are going to be saved.
@mitogh
mitogh / clearHistory.sh
Last active August 29, 2015 14:09
Clean the history of your downloads, (MAC)
#!/bin/bash
# Show all the current LOG of your history.
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineDataURLString from LSQuarantineEvent'
# Delete all the entries from the history.
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'
# Credits:
# http://lifehacker.com/your-mac-logs-everything-you-download-heres-how-to-cle-1658394180
Interesting Javascript puzzle (from a recent programming contest):
How do you create a number 100000000000000000000 in Javascript using only these four characters: '+', '!', '[', ']' and you can only use at most 60 such characters?
Some hints:
+!![] is equal to number 1
+!![]+!![] is equal to number 2
(don't answer if you participated in that contest)
FYI, the answer is super tricky and close to "cheating".
@mitogh
mitogh / states.txt
Last active January 23, 2016 21:40
US States
AL : Alabama
AK : Alaska
AZ : Arizona
AR : Arkansas
CA : California
CO : Colorado
CT : Connecticut
DE : Delaware
FL : Florida
GA : Georgia
@mitogh
mitogh / functions.php
Last active September 19, 2017 19:11
Upload assets to Wordpress
<?php
function upload_asset( $location, $post_id ) {
$timeout_seconds = MINUTE_IN_SECONDS * 10;
$tmp_file = download_url( $location, $timeout_seconds );
if ( is_wp_error( $tmp_file ) ) {
@unlink( $tmp_file );
return false;
}
$type = wp_check_filetype( $tmp_file );
<?php
/*
* EXAMPLE OF CHANGING ANY TEXT (STRING) IN THE EVENTS CALENDAR
* See the codex to learn more about WP text domains:
* http://codex.wordpress.org/Translating_WordPress#Localization_Technology
* Example Tribe domains: 'tribe-events-calendar', 'tribe-events-calendar-pro'...
*/
function tribe_custom_theme_text( $translation, $text, $domain ) {
// If this text domain doesn't start with "tribe-", "the-events-", or "event-" bail.
if ( ! ( strpos( $domain, 'tribe-' ) !== false || strpos( $domain, 'the-events-' ) !== false || strpos( $domain, 'event-' ) !== false ) ) {
@mitogh
mitogh / examples.md
Last active March 22, 2022 00:17
Filter description

Usages examples

Filter: webp_uploads_img_url_mime_type

add_filter(
	'webp_uploads_img_url_mime_type',
	function ( $replacement, $attachment_id, $size_name, $mime_type, $image_tag ) {
 // Plugin is interested only on WebP.
@mitogh
mitogh / endpoint.php
Created April 4, 2022 02:05
Creates a custom image size with the provided dimensions
add_action( 'rest_api_init', function () {
register_rest_route(
'wp/v2',
'/media/(?P<id>[\d]+)/custom',
array(
'methods' => 'GET',
'args' => array(
'id' => array(
'validate_callback' => function ( $id ) {
if ( ! is_numeric( $id ) ) {