Skip to content

Instantly share code, notes, and snippets.

View paslandau's full-sized avatar
💭
¯\_(ツ)_/¯

Pascal Landau paslandau

💭
¯\_(ツ)_/¯
View GitHub Profile
@paslandau
paslandau / guzzle-append-requests-on-the-fly-generator-vs-retry.php
Created April 12, 2015 08:40
Example of appending requests on the fly using an ArrayIterator as generator and comparing that approach to $event->retry() and $client->send()
<?php
/** CAUTION!!!
* You need to have a webserver running on localhost to make this work!
*/
use GuzzleHttp\Client;
use GuzzleHttp\Event\AbstractRetryableEvent;
use GuzzleHttp\Message\Request;
use GuzzleHttp\Pool;
@paslandau
paslandau / result.txt
Created June 30, 2017 15:42
crawling result
https://www.aboutyou.at/ with Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
HTTP/1.1 302 Found
Location: https://m.aboutyou.at/
HTTP/1.1 200 OK
https://www.aboutyou.ch/ with Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
HTTP/1.1 302 Found
Location: https://m.aboutyou.ch/
HTTP/1.1 200 OK
@paslandau
paslandau / redirect.sh
Created June 30, 2017 15:39
Bash script to check geo- and mobile redirects for aboutyou de/at/ch when using Googlebot user agents
y="at
ch
de"; \
x="
Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Googlebot/2.1 (+http://www.google.com/bot.html)
"; \
IFS="\n"; readarray -t countries <<<"$y";\
readarray -t userAgents <<<"$x"; IFS=""; \ for y in ${userAgents[@]}; do for x in ${countries[@]}; do url="https://www.aboutyou.${x}/"; printf "\n$url with $y\n"; curl -sIL -H "user-agent: $y" $url 2>&1 | egrep 'HTTP/1.1|Location|Failed'; done; done;
@paslandau
paslandau / php-encoding-test.php
Last active January 10, 2018 10:45
Weird behaviour when changing the different php.ini settings to influence the default mb_internal_encoding() encoding.
<?php
echo "\n\nPHP: " . phpversion()."\n";
echo "Default: " . mb_internal_encoding()."\n";
echo "Old value of default_charset: ".ini_set("default_charset", "ASCII")."\n";
echo "when default_charset is set to ASCII: " . mb_internal_encoding()."\n";
echo "Old value of internal_encoding: ".ini_set("internal_encoding", "ASCII")."\n";
echo "when internal_encoding is set to ASCII: " . mb_internal_encoding()."\n";
echo "Old value of mbstring.mb_internal_encoding: ". ini_set("mbstring.internal_encoding", "ASCII")."\n";
echo "when mbstring.internal_encoding is set to ASCII: " . mb_internal_encoding()."\n";
@paslandau
paslandau / isDirtyFix.php
Last active September 18, 2018 22:31
Dirty fix for Model::isDirty() in Laravel to honor the $casts attribute
<?php
/**
* Determine if the model or given attribute(s) have been modified.
*
* @param Model $m
* @param array|string|null $attributes
* @return bool
*/
function _is_dirty(Model $m, $attributes = null){
@paslandau
paslandau / convert-timestamp-to-different-timezone.sql
Last active June 28, 2019 06:21
Convert timestamp/date/datetime to different timezone in BigQuery
#standardSQL
# Convert date / time to a different timezone in BigQuery; standard-sql; 2018-04-08
# @see http://www.pascallandau.com/bigquery-snippets/convert-timestamp-date-datetime-to-different-timezone/
WITH examples AS (
SELECT TIMESTAMP("2018-04-08T15:50:10+00:00") AS timestamp # Daylight saving time
UNION ALL SELECT TIMESTAMP("2018-03-08T15:50:10+00:00") # Standard time
)
SELECT
timestamp,
DATETIME(timestamp) as datetime,
@paslandau
paslandau / use-variables.sql
Last active May 29, 2020 19:00
Declare and use variables in BigQuery
-- Declare and use variables in BigQuery; 2020-05-29
-- @see http://www.pascallandau.com/bigquery-snippets/use-variables/
DECLARE foo_var STRING DEFAULT "foo";
SELECT foo_var
@paslandau
paslandau / use-temporary-tables-with-named-subquery.sql
Last active May 29, 2020 19:40
Using temporary tables via WITH (named subqueries) in Google BigQuery
-- Using temporary tables via WITH (named subqueries) in Google BigQuery; 2020-05-29
-- @see http://www.pascallandau.com/bigquery-snippets/use-temporary-tables-with-named-subquery/
WITH data as (
SELECT
1 as id,
DATE("2018-04-08") AS date,
UNION ALL SELECT 2, DATE("2018-04-09")
UNION ALL SELECT 3, DATE("2018-04-10")
UNION ALL SELECT 4, DATE("2018-04-11")
),
@paslandau
paslandau / expression-subqueries-for-nested-repeated-fields.sql
Last active May 29, 2020 20:10
How to use expression subqueries to query nested and repeated fields in Google BigQuery
-- Using expression subqueries to query nested and repeated fields in Google BigQuery; 2020-05-29
-- @see http://www.pascallandau.com/bigquery-snippets/expression-subqueries-for-nested-repeated-fields/
WITH example as (
SELECT
1 as id,
[
STRUCT("foo" as key, "foo 1" as value),
STRUCT("bar" as key, "bar 1" as value)
] AS data,
UNION ALL
@paslandau
paslandau / monitor-query-costs-in-bigquery-example.sql
Last active November 4, 2021 12:45
Monitor Query Costs in BigQuery via INFORMATION_SCHEMA views
# Monitor Query costs in BigQuery; standard-sql; 2020-06-21
# @see http://www.pascallandau.com/bigquery-snippets/monitor-query-costs/
DECLARE timezone STRING DEFAULT "Europe/Berlin";
DECLARE gb_divisor INT64 DEFAULT 1024*1024*1024;
DECLARE tb_divisor INT64 DEFAULT gb_divisor*1024;
DECLARE cost_per_tb_in_dollar INT64 DEFAULT 5;
DECLARE cost_factor FLOAT64 DEFAULT cost_per_tb_in_dollar / tb_divisor;
SELECT