Skip to content

Instantly share code, notes, and snippets.

View goreilly's full-sized avatar

Garrett O'Reilly goreilly

  • San Francisco, CA
View GitHub Profile
@goreilly
goreilly / macros.twig
Created May 19, 2015 15:39
Twig HTML Select Macro with optgroups
{% macro select (name, id, options, selected, required, includeBlank) %}
<select name="{{ name }}" id="{{ id }}" {{ required ? 'required' : '' }}>
{% if includeBlank %}
<option value=""></option>
{% endif %}
{% for key, value in options %}
{% if value is iterable %}
<optgroup label="{{ key }}">
{% for subKey, subValue in value %}
<option value="{{ subKey }}" {{ subKey == selected ? 'selected' : '' }}>{{ subValue }}</option>
/**
* Note: Also removes anything after the _ in the key. Useful for
* adding nodes with the same name. e.g. Node_1 and Node_2 both become Node.
* Appends child to argument by reference.
* @param array $element
* @param \SimpleXMLElement $parent
* @return \SimpleXMLElement
*/
protected function arrayToXml (array $element, \SimpleXMLElement $parent) {
foreach ($element as $key => $child) {
# When someone tries to login as root...
Match User root
# Denys all access except root@10.0.0.10
AllowUsers root@10.0.0.10
# See: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man5/sshd_config.5?query=sshd%5fconfig&sec=5
@goreilly
goreilly / pagination.html.twig
Last active March 23, 2016 15:21
Use Knp Sliding Pagination from any template
{# Replicate \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination::getPaginationData #}
{% set range = range ?? 5 %}
{% if pageCount < current %}
{% set current = pageCount %}
{% endif %}
{% if range > pageCount %}
{% set range = pageCount %}

Keybase proof

I hereby claim:

  • I am goreilly on github.
  • I am goreilly (https://keybase.io/goreilly) on keybase.
  • I have a public key whose fingerprint is FB90 8739 39D7 552B 633A 69F4 3878 74DE 3207 89A9

To claim this, I am signing this object:

---
##
# Invoke any type of script to modify files. Dry-run friendly usually.
# remote_path: Path to file on server.
# script: Commands that returns altered content on stdout
##
- name: get current content
always_run: yes
register: remote
@goreilly
goreilly / composer.json
Last active September 22, 2016 18:10
ansible generate symfony parameters.yml
{
"require": {
"symfony/yaml": "2.2"
}
}
@goreilly
goreilly / Batch manage and version host keys with ansible.md
Last active October 7, 2016 16:41
Batch manage and version host keys with ansible

Batch manage and version host keys with ansible

$ ansible-playbook tool_known_hosts.yml

./tool_known_hosts.yml

---
- hosts: localhost
@goreilly
goreilly / .my.cnf
Created October 25, 2016 22:07
Import entire MySQL databases from command live over SSH tunnel
[client]
user=root
password=password
host=127.0.0.1
port=3306
[clientremote]
user=remote_username
password=remote_password
host=127.0.0.1
port=3307
@goreilly
goreilly / dif.php
Created January 10, 2017 19:13
Generate Data Interchange Format from key value array source
<?php
$data = [
[
'hello' => 'world',
'world' => 'hello',
],
[
'hello' => '12387293871293847123894712342134',
'world' => '12387293871293847123894712342134',