Skip to content

Instantly share code, notes, and snippets.

View artpi's full-sized avatar

Artur Piszek artpi

View GitHub Profile
public function curl($Url,$args = array()) {
//Translate get params.
if(count($args)>0) {
$tab=array();
while (list($key, $value) = each($args)) {
$tab[]=$key."=".$value;
}
$get="?".implode("&",$tab);
} else {
var filendir = require('filendir');
function define(fileName, args, func) {
var content = '';
if (typeof func === 'function') {
content = "define('" + fileName + "', \n" + JSON.stringify(args).replace(/,/g, ",\n") + ", \n" + func.toString() + "\n);";
} else if (typeof args === 'function') {
content = "define('" + fileName + "',\n" + args.toString() + "\n);";
}
filendir.ws(fileName + ".js", content);
}
@artpi
artpi / alfred evernote snippets
Last active February 10, 2018 17:39
Alfred Evernote Snippets
============================
Script filter:
var q = "{query}";
var values = Application('Evernote').findNotes("notebook:Snippets " + q);
var ret = '<?xml version="1.0"?><items>';
for (var i=0; i<values.length; i++ ) {
var title = values[i].title();
var val = values[i].htmlContent().replace(/<br\/>/g,'{enter}').replace(/<[^>]*?>/g,"");
@artpi
artpi / btc-eth-dca-buy.php
Last active October 14, 2021 16:39 — forked from levelsio/btc-eth-dca-buy.php
This script runs daily and "Dollar Cost Average"-buys $40 BTC and $10 ETH per day
<?php
// Forked from @levelsio
function generateBitstampSignature( $nonce ) {
$message = $nonce . BITSTAMP_ID . BITSTAMP_KEY;
return strtoupper( hash_hmac( 'sha256', $message, BITSTAMP_SECRET ) );
}
@artpi
artpi / gist:a5f1d7c39bc0207e1163f3cb04ae6049
Created January 12, 2018 08:28
Download kindle my clippings file and parse them
class MyClippings extends Shortcode {
public $name = "my-clippings";
static $clippings;
static function load_clippings() {
if( ! self::$clippings ) {
self::$clippings = file_get_contents( "https://drive.google.com/uc?export=download&id=[SOME FILE ID FROM Gdrive]" );
}
}
function process( $filter ) {
self::load_clippings();
@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 ) );
}
@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 / 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
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;