Skip to content

Instantly share code, notes, and snippets.

View magnetikonline's full-sized avatar
💡
I have an idea!

Peter Mescalchin magnetikonline

💡
I have an idea!
View GitHub Profile
@magnetikonline
magnetikonline / example.sh
Last active July 6, 2016 11:04
AWS EC2 extract IAM role data from HTTP instance data using bash & curl.
#!/bin/bash
IAM_BASE_URL="http://169.254.169.254/latest/meta-data/iam/security-credentials"
IAMRoleName=$(curl -s $IAM_BASE_URL/)
IAMRoleData=$(curl -s $IAM_BASE_URL/$IAMRoleName/)
IAMRoleAccessKeyID=$(echo -n "$IAMRoleData" | sed -nr 's/.*?"AccessKeyId"[^"]+"([^"]+)",?/\1/p')
IAMRoleAccessKeySecret=$(echo -n "$IAMRoleData" | sed -nr 's/.*?"SecretAccessKey"[^"]+"([^"]+)",?/\1/p')
IAMRoleToken=$(echo -n "$IAMRoleData" | sed -nr 's/.*?"Token"[^"]+"([^"]+)",?/\1/p')
@magnetikonline
magnetikonline / run.sh
Last active August 29, 2015 14:05
Testing jpegtran (libjpeg-turbo) vs. mozjpeg compression abilities on a set of source JPEGs.
#!/bin/bash
rm turbo/*
rm mozjpeg/*
cd orig/
echo libjpeg-turbo
find . -name "*.jpg" -exec jpegtran -optimize -copy none -outfile "{}.tmp" "{}" \; -exec mv "{}.tmp" "../turbo/{}" \;
echo Done
@magnetikonline
magnetikonline / README.md
Last active August 29, 2015 14:05
AWS s3curl.pl example.

AWS s3curl.pl example usage

Perl wrapper script for curl from Amazon to GET/PUT items to/from S3 buckets, adding the required headers to the curl command line.

Download: http://aws.amazon.com/code/128

Listing a bucket

$ chmod u+x s3curl.pl
$ ./s3curl.pl \
	--id [AWS_KEY] \
@magnetikonline
magnetikonline / README.md
Last active August 29, 2015 14:05
XBMC update library paths.

XBMC update library paths

Taken from XBMC Wiki.

Video library

SQL

UPDATE art SET url = REPLACE(url,'nfs://192.168.0.2/','nfs://nas/');
UPDATE episode SET c18 = REPLACE(c18,'nfs://192.168.0.2/','nfs://nas/');
UPDATE movie SET c22 = REPLACE(c22,'nfs://192.168.0.2/','nfs://nas/');
@magnetikonline
magnetikonline / README.md
Last active August 29, 2015 14:05
PHP array addition examples.

PHP array addition

Example script

<?php
$first = [
	'one' => 'first',
	'two' => 'first',
	'three' => 'first'
];
@magnetikonline
magnetikonline / README.md
Last active August 29, 2015 14:03
Install Windows 7 ISO to USB key.

Install Windows 7 ISO to USB key

Plug in USB key and get device name:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             110G   34G   71G  33% /
udev                  7.9G  4.0K  7.9G   1% /dev
tmpfs 1.6G 1.5M 1.6G 1% /run
@magnetikonline
magnetikonline / example.php
Last active July 11, 2018 01:31
Unicorns.
<?php
class TestClass {
public function generator() {
$this->curlRequestThingy(
'http://domain.com/endpoint',
// function here passed to CURLOPT_WRITEFUNCTION
function($data) {
@magnetikonline
magnetikonline / dumprequest.php
Last active March 21, 2025 08:29
PHP script to dump full HTTP request to file (method, HTTP headers and body).
<?php
// https://gist.github.com/magnetikonline/650e30e485c0f91f2f40
class DumpHTTPRequestToFile {
public function execute($targetFile) {
$data = sprintf(
"%s %s %s\n\nHTTP headers:\n",
$_SERVER['REQUEST_METHOD'],
$_SERVER['REQUEST_URI'],
$_SERVER['SERVER_PROTOCOL']
@magnetikonline
magnetikonline / Dockerfile
Last active August 14, 2023 19:23
Dockerfile Ubuntu apt-get AU mirror switching.
FROM ubuntu:18.04
LABEL maintainer="Peter Mescalchin <[email protected]>"
RUN sed --in-place --regexp-extended "s/(\/\/)(archive\.ubuntu)/\1au.\2/" /etc/apt/sources.list && \
apt-get update && apt-get upgrade --yes