Skip to content

Instantly share code, notes, and snippets.

View marijn's full-sized avatar

Marijn Huizendveld marijn

View GitHub Profile
@marijn
marijn / Example.php
Created April 3, 2012 16:53
An example on sorting Doctrine\Common\Collection\ArrayCollection elements
<?php
$collection = new Doctrine\Common\Collection\ArrayCollection();
// add objects to the collection that contain a getCreated method returning a DateTime instance
$iterator = $collection->getIterator();
$iterator->uasort(function ($first, $second) {
if ($first === $second) {
@marijn
marijn / README.markdown
Last active May 3, 2024 14:09
List of nationalities in YAML, CSV and TXT format

List of nationalities

It's time someone compiled a list of nationalities to use within a web application. This gist attempts to make a first move at that.

List of countries

I've also compiled a list of countries

@marijn
marijn / README.markdown
Last active October 1, 2023 13:42
List of countries in YAML, CSV and TXT format
@marijn
marijn / unshorten.php
Created October 16, 2012 20:52
Unshorten URLS with PHP and CURL
<?php
/**
* @link http://jonathonhill.net/2012-05-18/unshorten-urls-with-php-and-curl/
*/
function unshorten_url($url) {
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_FOLLOWLOCATION => TRUE, // the magic sauce
CURLOPT_RETURNTRANSFER => TRUE,
@marijn
marijn / apc.php
Created May 15, 2012 11:20
Default APC.php file for clearing the opcode cache etc.
<?php
/*
+----------------------------------------------------------------------+
| APC |
+----------------------------------------------------------------------+
| Copyright (c) 2006-2011 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
@marijn
marijn / terms-and-conditions-in-label.twig
Created November 23, 2012 21:54
This is how you add a link to a label with Symfony forms, sort of. Cause you'll have a label tag twice...
{% set terms_link %}<a title="{% trans %}Read the General Terms and Conditions{% endtrans %}" href="{{ path('get_general_terms_and_conditions') }}">{% trans %}General Terms and Conditions{% endtrans %}</a>{% endset %}
{% set general_terms_and_conditions %}{{ 'I have read and accept the %general_terms_and_conditions%.'|trans({ '%general_terms_and_conditions%': terms_link })|raw }}{% endset %}
<div>
{{ form_errors(form.acceptGeneralTermsAndConditions) }}
{{ form_widget(form.acceptGeneralTermsAndConditions) }}
<label for="{{ form.acceptGeneralTermsAndConditions.vars.id }}">{{ general_terms_and_conditions|raw }}</label>
</div>
@marijn
marijn / README.markdown
Created November 26, 2021 17:42
Replace numeric input element with select element on mobile devices

Something I wrote years ago but might still be useful. A simple script to replace numeric input elements with their equivalent select element to ease input on touch based devices.

@marijn
marijn / Placefill.js
Created October 27, 2017 14:21
Bookmarklet for filling out forms with placeholder data
javascript:(function%20()%20{%20function%20usePlaceholdersAsFormInput()%20{%20var%20fields%20=%20document.querySelectorAll('input[placeholder]');%20var%20cruft%20=%20/^E\.g\.\s+/;%20for%20(var%20i%20=%200,%20field;%20i%20<%20fields.length;%20i++)%20{%20field%20=%20fields.item(i);%20field.value%20=%20field.placeholder.replace(cruft,%20'');%20}%20}%20function%20selectFirstOptionFromMenus()%20{%20var%20menus%20=%20document.querySelectorAll('select');%20for%20(var%20i%20=%200,%20option;%20i%20<%20menus.length;%20i++)%20{%20option%20=%20menus.item(i).querySelector('option[value]');%20if%20(option)%20{%20option.selected%20=%20true;%20}%20}%20}%20usePlaceholdersAsFormInput();%20selectFirstOptionFromMenus();%20})();
@marijn
marijn / README.markdown
Created October 7, 2016 11:39
Sendgrid API response

Response 😭

HTTP/1.1 201 CREATED
Server: nginx
Date: Fri, 07 Oct 2016 11:34:45 GMT
Content-Type: application/json
Content-Length: 235
Connection: keep-alive
@marijn
marijn / README.markdown
Last active June 28, 2016 21:38
Attempt to build a projection of arriving guests based on the events from the Projections Explained workshop.