Skip to content

Instantly share code, notes, and snippets.

@yoyosan
yoyosan / swap.md
Last active March 28, 2022 11:05
Enabling swap on Scaleway or any other VPS

It seems all new scaleway servers are created without swap. For people, like me who want to use some, there is the easy way (ex. is for 8Go) :

sudo dd if=/dev/zero of=/swap bs=1024 count=8388608
sudo chmod 0600 /swap
sudo mkswap /swap
sudo swapon /swap
free -h
@bohwaz
bohwaz / setcookie_samesite_polyfill.php
Last active September 4, 2018 13:56
PHP setcookie function polyfill with support for SameSite attribute (compatible with PHP 5.0+)
<?php
/**
* Setcookie function with support for SameSite
* @param string|null $samesite 'Lax' or 'Strict'
*/
function setcookie_samesite($name, $value = '', $expire = 0, $path = null, $domain = null, $secure = false, $httponly = false, $samesite = null)
{
$params = array(
rawurlencode($name) . '=' . rawurlencode($value),
@staabm
staabm / FileSessionHandler.php
Last active February 12, 2023 20:20
Drop in replacement for the native php file session handler with lock-timeout support. Work arround PHP Bug #72345.
<?php
class FileSessionHandler implements SessionHandlerInterface
{
/**
* time in milliseconds how fast to poll the filesystem for a file-lock
* in case it cannot be acquired / is (b)locked by other resources.
*
* @var int
* @internal
@573
573 / leeter.hs
Created August 5, 2015 10:26
Funny enough - How I recovered my lost Keepass password (Windows version)
import Data.Char
import Data.List
-- here the potential variations/mutations on letters are stored/encoded
leets = ["oO0*;%&","aA4@;%&","lL1!;%&", "eE3;%&", "tT7;%&", "hHkK;%&", "iI1!;%&", "sS&5;%"]
leetchar c [] = nub [c, toUpper c, toLower c]
leetchar c (l:ls) = if c `elem` l then l else leetchar c ls
leet [] = return []
@mildred
mildred / download.sh
Created October 20, 2014 10:03
Download from archive.org Wayback Machine
#!/bin/bash
url=http://redefininggod.com
webarchive=https://web.archive.org
wget="wget -e robots=off -nv"
tab="$(printf '\t')"
additional_url=url.list
# Construct listing.txt from url.list
# The list of archived pages, including some wildcard url
@runeb
runeb / js-exif-rotate.html
Created May 23, 2014 10:49
Auto-rotate images locally in the browser by parsing exif data
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input id="file" type="file" accept="image/*" />
<br/>
<h2>As read:</h2>
<img id="placeholder1" width=300/><br/>
<h2>Rotated by exif data:</h2>
<img id="placeholder2" width=300/>
<script>
And what about pgettext and npgettext? They are there in the gettext documentation, but there aren't in PHP. They're very useful if you have the same messages for translation, but in different contexts, so they should be translated separately and probably differently.
Fortunately, there is a simple work-around, which may help:
From the gettext.h header one can find out that pgettext() is only a macro calling dcgettext() internally with properly mangled parameters - msgctxt and msgid are glued together with use of ASCII char 4 [EOT, End Of Text]. The same way they're written in .mo files, so it's possible to refer them this way.
Here's my "emulated" pgettext() function:
<?php
if (!function_exists('pgettext')) {
@onyxraven
onyxraven / nvsprintf.php
Last active November 13, 2019 11:48
Named param vsprintf()
<?php
/**
* Named-Param vsprintf()
*
* positional-params based on key name, much the same as positional in sprintf()
*
* @link http://php.net/manual/en/function.sprintf.php
* @link http://www.php.net/manual/en/function.vsprintf.php
*
* @param string $str format string - replacements are in %KEY$x format
@henrik
henrik / google_art_project.rb
Created February 5, 2011 23:22
I'M AFRAID THIS SCRIPT NO LONGER WORKS! MAYBE http://www.student.tugraz.at/kollmitzer/gap_howto.html OR https://github.com/EmelyanenkoK/GAPDownloader DOES. SEE COMMENTS. Google Art Project fullsize image downloader. Specify the page URL and the tiles are downloaded, stitched and trimmed.
# Google Art Project fullsize image downloader.
# By Henrik Nyh <http://henrik.nyh.se> 2011-02-05 under the MIT license.
# Requires Ruby and ImageMagick.
#
# NOTE:
# I'm afraid this script no longer works! See the Gist comments.
#
# Usage e.g.:
# ruby google_art_project.rb http://www.googleartproject.com/museums/tate/portrait-of-william-style-of-langley-174
#