Skip to content

Instantly share code, notes, and snippets.

View artpi's full-sized avatar

Artur Piszek artpi

View GitHub Profile
;; The app will show those queries in today's journal page,
;; the "NOW" query asks the tasks which need to be finished "now",
;; the "NEXT" query asks the future tasks.
;; Arturs comment: "A8C" is my work. I tag my work tasks with "A8C"
:default-queries
{:journals
[
{:title "🛠 TODO"
:query (and (or (todo TODO) (todo DOING) ) ( not [[LATER]] ) ( not [[FollowUp]] ) ( not [[A8C]] ) )
:collapsed? true}
// https://piszek.com/2013/03/13/walidacja-numeru-pesel-w-javascript/
// Funkcja dekodujaca nr. Pesel
function peselDecode(pesel) {
// Wycinamy daty z numeru
var rok = parseInt(pesel.substring(0, 2), 10);
var miesiac = parseInt(pesel.substring(2, 4), 10) - 1;
var dzien = parseInt(pesel.substring(4, 6), 10);
// Pesel został wprowadzony w 20 wieku, ale zawiera modyfikatory na przysłość
// Miesiąc zawiera dodatkowe liczby dla dat z przyszłości.
document.addEventListener("click", function ( e ) {
const target = e.target;
if (
target.tagName === "BUTTON" &&
target.innerText === 'WordPress'
) {
const id = target.closest('.roam-block').id;
const blockUid = id.substring(id.length - 9, id.length);
const data = window.roamAlphaAPI.q('[ :find (pull ?e [ :block/string :block/heading :block/order :block/children :block/refs :children/view-type {:block/children ...} {:block/refs [*]}]) :in $ ?uid :where [?e :block/uid ?uid]]', blockUid);
const text = blockToHTML( data[0][0] );
/**
* Troamback by @artpi - see:
* https://piszek.com/roam/troamback
* For installation, put in your [[roam/js]]. Detailed instructions above.
*
* This script will put a reference in your daily page to a random block with a special tag.
* For example, I will get a reference on my daily page to a random block tagged with "Grateful".
*/
// These are configurable:
@artpi
artpi / roam_todo_exploder.js
Last active April 28, 2022 01:19
This will animate an "Explosion" whenever you complete a TODO in Roam Research, so you can be productive in style.
// This will animate an "Explosion" whenever you complete a TODO in Roam Research.
// See https://deliber.at/roam for more Roam goodies.
// Put this file under {{[[roam/js]]}} block. I have a page roam/js. Under that, I have {{[[roam/js]]}} and under that the javascript block
document.addEventListener("click", function ( e ) {
const target = e.target;
if (
target.tagName === "INPUT" &&
target.parentElement.className === "check-container"
) {
if (target.type === "checkbox" && target.checked ) {
@artpi
artpi / functions.php
Created January 2, 2021 18:08
Embed Github Markdown files in WordPress
// Drop this in functions.php or your plugin.
// You NEED to have Parsedown.php also : https://github.com/erusev/parsedown
wp_embed_register_handler(
'github_readme_md',
'&https?:\/\/github\.com\/([a-zA-Z-_0-9/]+)\/([a-zA-Z]+)\.md&i',
__NAMESPACE__ . '\artpi_github_markdown_handler'
);
function artpi_github_markdown_handler( $matches, $attr, $url, $rawattr ) {
@artpi
artpi / functions.php
Last active December 25, 2020 08:07
Private podcast on WordPress
// put that in functions.php in your theme
add_filter( 'the_content', $content, 'private_podcast', 10, 1 );
function private_podcast( $content ) {
if( has_category( 'podcast' ) && ! has_access() ) {
return "This is a private podcast. Please subscribe here";
}
return $content;
}
function has_access() {
global $_GET;
@artpi
artpi / transcribe_audio_file_in_an_evernote_note.php
Last active May 27, 2020 09:09
Use Google Speech API to transcribe recordings in your Evernote Notes: https://piszek.com/2020/05/27/evernote-transcriber/
<?php
// https://piszek.com/2020/05/27/evernote-transcriber/
function transcribe_audio_file_in_a_note( $evernoteClient, $note ) {
// This will find the place where file is embedded, so we can display the transcription underneath.
if( preg_match( '#<en-media hash="([a-z0-9]+)"[^>]+>#is', $note->content, $res ) ) {
$id = hex2bin($res[1] );
$resources = array_filter( $note->resources, function( $resource ) use ( $id ) {
return $resource->data->bodyHash === $id;
} );
@artpi
artpi / functions.php
Created March 20, 2019 16:12
This page should be visible only for 48 hours since the first visit
// This page should be visible only for 48 hours since the first visit
// Drop this in functions.php
function make_the_page_visible_only_certain_time_after_first_visit() {
$secret_page = PAGE_ID_HERE;
$redirect_to_when_expired = URL_TO_REDIRECT;
$time_to_visit = 48 * 3600; //48h
if ( is_page( $secret_page ) && ! is_user_logged_in() ) {
if ( empty( $_GET[ 'visitor_id' ] ) ) {
wp_redirect( URL_OF_EXPIRED_PAGE );
@artpi
artpi / find-unused-functions.php
Created January 23, 2018 08:39
Find unused PHP functions
#!/usr/local/bin/php
<?php
function get_funcs( $dir ) {
if ( is_dir( $dir ) ) {
$files = scandir( $dir );
$funcs = array();
foreach ( $files as $file ) {
if ( substr( $file, 0, 1 ) !== '.' ) {
$funcs = array_merge( $funcs, get_funcs( $dir . "/" . $file ) );
}