Skip to content

Instantly share code, notes, and snippets.

@sjelfull
sjelfull / latency.markdown
Created February 9, 2016 11:46 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@sjelfull
sjelfull / zip.php
Created January 6, 2016 13:02 — forked from jonmaim/zip.php
PHP script to remotely create zip archives of your FTP
<?php
/*
*
* This script will backup your web site by remotely archiving all files on the root FTP directory.
* It will work even if your web server is memory limited buy splitting zips in several arhive files it they are too many files.
* All zip files will be stored in a directory called temporary which must be writable.
*
* How to use it:
* - Place the script at the root of your FTP.
@sjelfull
sjelfull / pthreads.md
Created November 15, 2015 23:52 — forked from krakjoe/pthreads.md
pthreads.md

Multi-Threading in PHP with pthreads

A Brief Introduction to Multi-Threading in PHP

  • Foreword
  • Execution
  • Sharing
  • Synchronization
  • Pitfalls
@sjelfull
sjelfull / Installing Imagick with PHP 7.md
Last active March 28, 2020 05:37
Installing Imagick with PHP 7

1. Download the phpseven branch of the imagick repository

git clone https://github.com/mkoppanen/imagick.git imagick

2. phpize for target PHP version

cd imagick && /path/to/php7/bin/phpize && ./configure && make && make install

3. Enable the extension for your PHP version

@sjelfull
sjelfull / expanded_craft_search.twig
Created October 4, 2015 01:42
Method for widening user search to include more results (show matches of only one word even if multiple are provided, and matching parts of words). Probably not a good idea for high traffic sites, but a blessing for standard ones.
{# Instead of using standard search, like that: #}
{% set query = craft.request.getParam('q') %}
{% set entries = craft.entries.search(query).order('score') %}
{# We can expand it to be more intuitive to the user and give better results: #}
{% set query = craft.request.getParam('q') %}
{# expand query by widening match from `xxx` to `*xxx*`, and `xxx yyy` to `*xxx* *yyy*`, etc #}
{% set expanded_query = query
| replace('/ {2,}/', ' ')
@sjelfull
sjelfull / TitleToSettingsPanePlugin.php
Last active August 29, 2015 14:25
Craft CMS: Simple (and not very well tested!) plugin to move the title field to the settings pane.
<?php
namespace Craft;
class TitleToSettingsPanePlugin extends BasePlugin {
/**
* Returns the plugin’s name.
*
* @return string The plugin’s name.
*/
@sjelfull
sjelfull / nav.html
Last active August 29, 2015 14:21 — forked from MisterPoppet/nav.html
{% macro menu(items, class, home) %}
{% import _self as parts %}
<div class="lucky {{ class|default('main') }} menu">
{% if home|default(true) %}
<a href="{{ siteUrl }}">Home</a>
{% endif %}
{{ parts.menuItems(items) }}
</div>
{% endmacro %}
<?php
namespace Craft;
class EntryTypeSourcesPlugin extends BasePlugin
{
public function getName()
{
return Craft::t('Entry Type Sources');
}
@sjelfull
sjelfull / csi-esi.js
Last active August 29, 2015 14:16 — forked from nikosd/csi-esi.js
/*
* ESI Parser 1.00 - Poor Man's ESI
*
* - or - I'm tired of seeing the wrong thing in my browser while developing.
*
* This code provides a client-side ESI parsing capability. It was created
* to provide an easier way of developing and testing sites that use ESI
* when not behind the cache or other system that provides the ESI parsing.
* It requires jQuery (anything after v1.2 should be fine)
*
@sjelfull
sjelfull / varnish-craft.vcl
Created February 19, 2015 13:01 — forked from aelvan/gist:eba03969f91c1bd51c40
Varnish 4.0 file for our Craft CMS projects
# Varnish 4.0 file for our Craft CMS projects
# Based on https://github.com/mattiasgeniar/varnish-4.0-configuration-templates/blob/master/default.vcl
#
# This is still work in progress, comments appreciated.
vcl 4.0;
import std;
import directors;