Skip to content

Instantly share code, notes, and snippets.

@pabloko
pabloko / ChooseFont0.md
Last active May 16, 2020 21:37
(C) ChooseFont color picker with extended color dialog

The ChooseFont dialog color picker extended

Using ChooseFont you will notice it only support 15 predefined an ugly colors. The color palette is very limited and theres no way to use more colors without subclassing it. Here is a good start point to subclass it, this mod will:

  • Display the color in HTML format
  • Display a full featured ChooseColor dialog when color ComboBox is clicked

@pabloko
pabloko / functions.php
Created April 20, 2020 13:32
[PHP/Wordpress] Define a default post password with filters and hooks
add_filter( 'post_password_required', function( $returned, $post )
{
//Define here your conditional logic, example filter posts without password from custom post type "photo_gallery"
if (empty($post->post_password) && $post->post_type=="photo_galery")
$post->post_password='Secretpw123';
//End of conditional logic. Returning true will ask for password, false will display the content.
require_once ABSPATH . WPINC . '/class-phpass.php';
$hasher = new PasswordHash( 8, true );
@pabloko
pabloko / 01.(PHP) Pre-processing MP3 Audio waveforms with big size.md
Created December 14, 2019 12:44
(PHP) Pre-processing MP3 Audio waveforms with big size

What?

When want to display audio waveform from audio file, you can find browser libraries like WavesurferJs, Squiggl, or whatever, everyone works the same:

  1. Load audio (in full) file and get its AudioContext
  2. Get all the raw PCM samples from one channel in Float32Array (huge) with something like ctx.decodeAudioData().getChannelData(0)
  3. Use drawing routine and average samples

Doing this process on the users browser is quite slow and wasteful in a magnitude proportional to the audio file size, as you have to fully load it then get huge amount of samples calculated in the drawing stage.

So one option to overcome this is to dump a shorter version of PCM data on a static file with an amount of samples enough to render the waveform and having a reasonable size by averaging the samples.

@pabloko
pabloko / 01.(JS) Half duplex XHR socket interface.md
Last active October 9, 2019 23:41
(JS) Half duplex XHR socket interface

(JS) Half duplex XHR socket interface

Advice: if you're looking to use this on production, better take a look at https://github.com/eBay/jsonpipe

Keeping the clients updated in real time apps is quite challenging sometimes, websockets or webrtc are great for this task, but usually what the developer want is to send most of the data well timed to the client, then recive a few commands from the client, so having full duplex socket in this scenario is quite wasteful, and may pose a security risk, at allowing the user to continuosly send arbitrary data. Polled ajax request, in the other hand cant be in any way correctly timed, so this function acts as an intermediante point between ajax requests and websockets.

This function needs a request that is kept alive then chunked data is being sent. It can be binary data, strings, or serializable json objects. You will have to place chunked headers Transfer-Encoding: chunked and ping regularly (5s should be fine) sending some data in order to maintain the conne

@pabloko
pabloko / WebBrowser.cpp
Last active March 16, 2016 21:00
Awesomium on Direct3D9 C++ class
#include "main.h"
#include "WebBrowser.h"
#include <direct.h>
CWebBrowser::CWebBrowser()
{
script = NULL;
webCore = NULL;
webView = NULL;
tWebPNG = NULL;