Skip to content

Instantly share code, notes, and snippets.

Avatar
🚗
Left Microsoft GitHub

daniel goldsmith dg01d

🚗
Left Microsoft GitHub
View GitHub Profile
@dg01d
dg01d / nginx.conf
Created May 20, 2018
Anonymised Nginx Logs
View nginx.conf
map $remote_addr $anon_remote_addr {
"~^(?<ip_a>\d+\.\d+)\.\d+\.\d+" "$ip_a";
}
log_format anonymised '$anon_remote_addr.0.0 - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
View webmention.html
{{ $mention_ids := index $.Site.Data.wm_io.index .URL }}
{{ $mentions := apply $mention_ids "index" $.Site.Data.wm_io.mentions "." }}
{{ $mentions := sort $mentions "wm-received" }}
{{ range $mentions }}
<ul>
{{- if or ("repost-of") ("like-of") }}
<li>Liked by {{ .author.name | markdownify }}</li>
{{- end}}
</ul>
{{ end }}
View gist:9ea3892231dff2159cf8dadb87ac73ee
PHP Warning: require(/srv/watchtower/vendor/composer/../../lib/config.php): failed to open stream: No such file or directory in /srv/watchtower/vendor/composer/autoload_real.php on line 66
PHP Fatal error: require(): Failed opening required '/srv/watchtower/vendor/composer/../../lib/config.php' (include_path='.:/usr/share/php') in /srv/watchtower/vendor/composer/autoload_real.php on line 66
@dg01d
dg01d / README.md
Created Feb 24, 2018
Micropub using emacs
View README.md

Credits

This is just an amendment for hjertnes' script

Notes

  • The setting mb-domain should be set to the full path of the micropub endpoint.
  • I could not get this to work using form-encoded post format. If your endpoint does not support json-encoded posts, this will likely not work.
View key_pop.php
/**
* Returns a value from an array and deletes
* the key=>value pair like python's s.pop['i']
*
* @param array $arr The array to be searched
* @param $key The search term
* @return The $value mapped to $key or null
*/
@dg01d
dg01d / yaml2json.php
Last active Dec 6, 2017
Quick'n'dirty script to convert a folder of YAML-frontmatter files to JSON-frontmatter
View yaml2json.php
<?php
require('vendor/autoload.php');
use Symfony\Component\Yaml\Parser;
$yaml = new Parser();
// Path for the content you want to convert
$files = glob('./micro/*.md');
View webmention.html
<script id="webmention-hosted">
(function () {
var sn = document.createElement("script"), s = document.getElementsByTagName("script")[0], url;
url = document.querySelectorAll ? document.querySelectorAll("link[rel~=canonical]") : false;
url = url && url[0] ? url[0].href : false;
sn.type = "text/javascript"; sn.async = true;
sn.src = "//webmention.herokuapp.com/api/embed?url=" + encodeURIComponent(url || window.location) + "&version=cutting-edge";
s.parentNode.insertBefore(sn, s);
}());
</script>
View microformats.php
<?php
function array_replace_keys(array $array, array $keys, $filter=false)
{
$newArray = array();
foreach($array as $key => $value) {
if (isset($keys[$key])) {
$newArray[$keys[$key]] = $value;
} elseif (!$filter) {
$newArray[$key] = $value;
@dg01d
dg01d / pelican2yaml.sh
Created Jan 25, 2017
A *hillariously* kludgey script to convert my pelican markdown files to hugo-parseable YAML format
View pelican2yaml.sh
#!/bin/bash
# Save standard output and standard error
exec 3>&1 4>&2
# Redirect standard output to a log file
exec 1>/tmp/stdout.log
# Redirect standard error to a log file
exec 2>/tmp/stderr.log
mkdir mod/
View www
# inside the ssl server block - no idea WHY this worked, but it DID:
location ~ /.well-known {
allow all;
}
#Server declaration for non-encrypted port 80
server {
listen 80;
server_name mysite.com www.mysite.com;
You can’t perform that action at this time.