Skip to content

Instantly share code, notes, and snippets.

@jurv
jurv / curltime.sh
Last active November 17, 2022 09:52
Bunch of tools
#!/bin/bash
# Curl a URL and display the different times of the request
curl -H 'Cache-Control: no-cache, no-store' -w @- -o /dev/null -s "$@" <<'EOF'
time_namelookup: %{time_namelookup}\n
time_connect: %{time_connect}\n
time_appconnect: %{time_appconnect}\n
time_pretransfer: %{time_pretransfer}\n
time_redirect: %{time_redirect}\n
@jurv
jurv / wkhtmltopdf.sh
Created February 9, 2017 10:08
Use session with wkhtmltopdf
wget --save-cookies cookies.txt --keep-session-cookies http://my-site.dev/app_dev.php/my/page
# It's possible to add option "--post-data 'user=foo&password=bar' " if you need to
# log in for exemple
# Then retrieve the session ID in cookie.txt
vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 \
--cookie 'sessionid' 'gfou6ks1lsguuvtk9il2v169n7' \
--cookie 'PHPSESSID' 'gfou6ks1lsguuvtk9il2v169n7' \
--debug-javascript \
@jurv
jurv / color.js
Created January 6, 2017 12:44
JS - Check if text color should be black or white, based on the background color
function shouldTextBeBlack (backgroundcolor) {
return computeLuminence(backgroundcolor) > 0.179;
}
function computeLuminence(backgroundcolor) {
var colors = hexToRgb(backgroundcolor);
var components = ['r', 'g', 'b'];
for (var i in components) {
var c = components[i];
@jurv
jurv / addcol.sql
Last active January 24, 2017 12:58
MySQL safe operations
DROP PROCEDURE IF EXISTS addcol;
delimiter '//'
CREATE PROCEDURE addcol() BEGIN
IF NOT EXISTS(
(
SELECT * FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA=DATABASE()
AND TABLE_NAME='my_table'
AND COLUMN_NAME='value4'
)