Skip to content

Instantly share code, notes, and snippets.

var http = require('http');
var options = {
host: 'www.google.co.uk',
path: '/',
port: '80',
//This is the only line that is new. `headers` is an object with the headers to request
headers: {'auth': 'abc:123'}
};
<?php
require_once('vendor/autoload.php');
use Symfony\Component\Yaml\Yaml;
$config = Yaml::parse(file_get_contents('config.yaml'));
$json = file_get_contents('php://input');
$object = json_decode($json);
@thomaslorentsen
thomaslorentsen / pca.js
Last active February 24, 2020 17:13
Custom integration of post code anywhere
pca.on("load", function (type, id, control) {
control.listen("populate", function (address) {
console.log('here');
});
});
<?php
require 'vendor/autoload.php';
$manager = new MongoDB\Driver\Manager("mongodb://192.168.33.96:27017");
$collection = new MongoDB\Collection($manager, "phplib_demo.write", 'test');
$result = $collection->insertOne(array(
'firstname' => 'hello',
'lastname' => 'world',
@thomaslorentsen
thomaslorentsen / cannotacccess.php
Created September 28, 2016 15:04
Replicates the cannot access variable error
<?php
class Foo {
function __construct() {
$foo = "\0";
$this->{$foo} = 'hello';
}
}
$f = new Foo();
<?php
// @see http://php.net/manual/en/class.generator.php
// @see http://php.net/manual/en/class.generator.php
function getRange ($max = 10) {
for ($i = 1; $i < $max; $i++) {
yield $k => $i;
}
}
@thomaslorentsen
thomaslorentsen / main.yaml
Created December 7, 2016 17:11
Installs XDebug
- name: Install XDebug
yum:
name: php-pecl-xdebug
state: present
- name: Set XDebug module location
lineinfile:
dest: /etc/php.d/xdebug.ini
regexp: '^zend_extension='
line: 'zend_extension=/usr/lib64/php/modules/xdebug.so'
@thomaslorentsen
thomaslorentsen / common_unzip_tasks_main.yml
Last active April 7, 2017 12:16
Only install unzip if directories do not exist
---
- block:
- name: test files exist
stat:
path: "{{ item }}"
register: directory_exists
changed_when: directory_exists.stat.exists == false
with_items: "{{ target_directories }}"
- name: install unzip
@thomaslorentsen
thomaslorentsen / GO.md
Last active November 2, 2017 16:00
Go Conference 2017 Notes
@thomaslorentsen
thomaslorentsen / minishift.md
Last active October 20, 2017 13:18
MiniShift

Install MiniShift

brew cask install minishift

The upgrade MiniShift with:

minishift update