Skip to content

Instantly share code, notes, and snippets.

View colinodell's full-sized avatar

Colin O'Dell colinodell

View GitHub Profile
@colinodell
colinodell / _description.md
Last active May 28, 2016 14:34
array_change_keys()

Problem

AFAIK, there are no core PHP methods which allow you to re-key an array.

Okay, that's not entirely true - there is array_change_key_case(), but whenever I need to change an array's keys it's never been this use case.

You could do it with a foreach loop:

$newArray = [];
@colinodell
colinodell / benchmark.php
Created May 30, 2016 00:46
array_change_keys() benchmark
<?php
$a = range(1, 10000000);
echo "Test 1 - Using foreach\n";
$start = microtime(true);
$b = [];
foreach ($a as $k => $v) {
$b[md5($v)] = $v;
@colinodell
colinodell / CustomParagraphRenderer.php
Created February 6, 2017 14:40
CommonMark - Overriding default renderers
<?php
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\ElementRendererInterface;
class CustomParagraphRenderer implements BlockRendererInterface
{
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
{
return $htmlRenderer->renderInlines($block->children());
@colinodell
colinodell / patch-01-requirements.diff
Created May 22, 2017 02:48
Custom open-wave build for Home Assistant 0.45 on Docker
diff --git a/requirements_all.txt b/requirements_all.txt
index 6141e3d..2da4ce0 100644
--- a/requirements_all.txt
+++ b/requirements_all.txt
@@ -695,9 +695,6 @@ python-vlc==1.1.2
# homeassistant.components.wink
python-wink==1.2.4
-# homeassistant.components.zwave
-python_openzwave==0.4.0.31
<?php
class TargetBlankLinkProcessor implements DocumentProcessorInterface
{
/**
* @param Document $document
*
* @return void
*/
public function processDocument(Document $document)
@colinodell
colinodell / changes.diff
Last active August 19, 2017 20:44
openzwave "dev" branch support for HA 0.50.2+
diff --git a/Dockerfile b/Dockerfile
index f0d5acc..fa6e914 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -31,6 +31,12 @@ COPY requirements_all.txt requirements_all.txt
RUN pip3 install --no-cache-dir -r requirements_all.txt && \
pip3 install --no-cache-dir mysqlclient psycopg2 uvloop cchardet
+# Install python-openzwave
+RUN pip3 install --upgrade cython==0.24.1 && \
@colinodell
colinodell / data.json
Last active October 30, 2017 04:16
Elephpants in JSON format
{
"2014-11-27-black-amsterdamphp": {
"name": "MurPHPy",
"variation": "AmsterdamPHP",
"species": "Elephpas hypertextus amstelodami",
"color": "black",
"sponsor": "AmsterdamPHP",
"reverse": "AmsterdamPHP logo",
"photos": [
{
@colinodell
colinodell / Dockerfile
Created October 12, 2017 19:39
Home Assistant with up-to-date Z-Wave files
FROM homeassistant/home-assistant:latest
RUN set -e && \
apt update && \
apt install -y unzip && \
wget -O /tmp/ozw.zip https://github.com/OpenZWave/open-zwave/archive/master.zip && \
cd /tmp && \
unzip /tmp/ozw.zip && \
cp -R /tmp/open-zwave-master/config/* /usr/local/lib/python3.6/site-packages/python_openzwave/ozw_config/ && \
rm -rf /tmp/ozw.zip /tmp/open-zwave-master && \
@colinodell
colinodell / .gitconfig
Created March 19, 2018 14:36
Git Aliases
[alias]
p = "!git pull --ff-only"
fixup = !sh -c 'REV=$(git rev-parse $1) && git commit --fixup $@ && git rebase -i --autostash --autosquash $REV^' -
cleanup = "!git branch --merged | grep -v -P '^\\*|master|develop' | xargs -n1 -r git branch -d"
children = "!bash -c 'c=${1:-HEAD}; set -- $(git rev-list --all --not \"$c\"^@ --children | grep $(git rev-parse \"$c\") ); shift; echo $1' -"

My Solutions for https://returntrue.win

  1. !0
  2. str_rot13
  3. !0
  4. 0
  5. 🤷 (any emoji should work)
  6. ???
  7. (object)[!0]
  8. new class extends Bar{}