Skip to content

Instantly share code, notes, and snippets.

View kasparsd's full-sized avatar

Kaspars Dambis kasparsd

View GitHub Profile
@kasparsd
kasparsd / ms-cron-runner.php
Last active March 16, 2023 19:00
Cron for WordPress Multisite
<?php
// Author: Kaspars Dambis <hi@kaspars.net>
// Usage: php ms-cron-runner.php --domain=example.com [--path=/path/to/wordpress]
// We can't run this reliably from CLI because of how WordPress
// relies on $_SERVER for loading functions.php
if ( php_sapi_name() !== 'cli' )
die;
@kasparsd
kasparsd / extract-twitter-username.php
Created August 6, 2015 13:34
Extract Twitter username from links to Twitter profiles
<?php
$html = file_get_contents( 'http://example.com' );
preg_match_all( '/https?:\/\/(?:www.)?twitter.com\/#?([a-zA-Z0-9_]+)\/?(?![\/a-z]+)/i', $html, $maybe_twitters );
if ( ! empty( $maybe_twitters[1] ) ) {
printf( 'Found %s', $maybe_twitters[1][0] );
} else {
print( 'Nothing found!' );
@kasparsd
kasparsd / index.html
Last active June 12, 2023 05:18
Get user timezones using Slack API
<!doctype html>
<html ng-app="timezoneApp">
<head>
<title>Team Timezones</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script>
var period = 172800; // 2 days in seconds
var now = new Date();
var utc = new Date( now.getTime() + now.getTimezoneOffset() * 60000 );
var seconds_today = utc.getSeconds() + ( 60 * ( utc.getMinutes() + ( 60 * utc.getHours() ) ) );
@kasparsd
kasparsd / prepare-commit-msg
Last active September 23, 2015 18:27
Prepend the current Git branch name and the JIRA parent issue to every commit message
#!/bin/bash
#
# Prepend the current branch name to every commit message.
# Prepend the parent issue from JIRA, if found.
#
# Save this to .git/hooks/prepare-commit-msg and make it exacutable:
# chmod +x .git/hooks/prepare-commit-msg
#
# Extract the current working branch
@kasparsd
kasparsd / index.php
Last active July 3, 2021 00:22
Convert .mo to .po and .po to .mo
<?php
session_start();
$_SESSION['last_post'] = time();
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Online Tools for WordPress Developers</title>
@kasparsd
kasparsd / disable-capture.php
Created October 2, 2015 05:38
Disable form submissions storage for a form ID
<?php
add_action( 'wpcf7_before_send_mail', function( $cf7 ) {
// Disable form submission for form ID 123
if ( 123 == $cf7->id() ) {
remove_action( 'wpcf7_before_send_mail', array( cf7_storage::instance(), 'storage_capture' ) );
}
}, 5, 1 );
<?php
add_filter( 'cf7_entry_rows', function( $rows, $entry ) {
$attachments = get_post_meta( $entry->ID, 'mail_attachments', true );
if ( empty( $attachments ) ) {
return $rows;
}
@kasparsd
kasparsd / pick-sub-feedly-bookmarklet.js
Last active October 2, 2015 09:28
Pick feed and subscribe in Feedly
javascript:void%20function(){var%20e=document.getElementsByTagName(%22link%22);for(li%20in%20e)if(e[li].rel%26%26(-1!==e[li].type.indexOf(%22rss+xml%22)||-1!==e[li].type.indexOf(%22atom+xml%22))%26%26confirm(e[li].href))return%20void%20window.open(%22http://feedly.com/i/subscription/feed/%22+e[li].href,%22_blank%22);alert(%22No%20valid%20feeds%20found!%22)}();
@kasparsd
kasparsd / gd-info.php
Created October 24, 2015 20:13
GD on PHP7
<?php
// Output of gd_info()
Array
(
[GD Version] => bundled (2.1.0 compatible)
[FreeType Support] =>
[GIF Read Support] => 1
[GIF Create Support] => 1
[JPEG Support] =>
@kasparsd
kasparsd / not-working.log
Last active October 29, 2015 12:21
OpenSC IAS/ECC output of Latvia eID
0x7fff7b564000 14:21:04.140733193388674 [opensc-tool] sc.c:251:sc_detect_card_presence: called
0x7fff7b564000 14:21:04.140733193388674 [opensc-tool] reader-pcsc.c:384:pcsc_detect_card_presence: called
0x7fff7b564000 14:21:04.642 [opensc-tool] reader-pcsc.c:294:refresh_attributes: OMNIKEY AG Smart Card Reader check
0x7fff7b564000 14:21:04.643 [opensc-tool] reader-pcsc.c:313:refresh_attributes: returning with: 0 (Success)
0x7fff7b564000 14:21:04.140733193388675 [opensc-tool] reader-pcsc.c:389:pcsc_detect_card_presence: returning with: 5
0x7fff7b564000 14:21:04.643 [opensc-tool] sc.c:256:sc_detect_card_presence: returning with: 5
Using reader with a card: OMNIKEY AG Smart Card Reader
0x7fff7b564000 14:21:04.643 [opensc-tool] sc.c:251:sc_detect_card_presence: called
0x7fff7b564000 14:21:04.140733193388675 [opensc-tool] reader-pcsc.c:384:pcsc_detect_card_presence: called
0x7fff7b564000 14:21:04.643 [opensc-tool] reader-pcsc.c:294:refresh_attributes: OMNIKEY AG Smart Card Reader check