Skip to content

Instantly share code, notes, and snippets.

View StefanoCappellini's full-sized avatar

Stefano Cappellini StefanoCappellini

View GitHub Profile
@StefanoCappellini
StefanoCappellini / functions.php
Last active November 18, 2021 01:01
How to speed up you your Divi gallery if you are using only the first thumbnail. See the related post here: https://www.stefanocappellini.it/posts/posts/make_divi_galleries_run_faster_without_thumbnails/
<?php
// Add this to your Divi child theme' functions.php file
// Remember to add the my_divi_fast_gallery class to all the galleries you want to optimize
add_filter('do_shortcode_tag', 'fast_gallery_tip', 105, 2);
function fast_gallery_tip($output, $tag){
if('et_pb_gallery' === $tag && strpos($output, 'my_divi_fast_gallery') !== false){
$pattern = '/<img[^>]*>/';
$index = 0;
return preg_replace_callback($pattern, function($matches) use (&$index) {
@StefanoCappellini
StefanoCappellini / java_multiple_hashing.java
Last active July 23, 2018 14:16
Python hashlib is twice as fast as Java MessageDigest: see the related post here: http://cppsfn.co/hashlib-vs-messagedigest
public static double comparison(int desiredSize, int bufferSize){
int size = desiredSize / bufferSize * bufferSize;
byte data[] = new byte[size];
new Random().nextBytes(data);
long startTime = 0;
long endTime = 0;
int nRounds = 10;
double elapsed = 0;
for(int round = 0; round < nRounds; round++){
MessageDigest sha = MessageDigest.getInstance("SHA-256");
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.