Skip to content

Instantly share code, notes, and snippets.

View kosso's full-sized avatar

Kosso kosso

View GitHub Profile
@kosso
kosso / custom-types-and-fields.php
Last active April 8, 2024 10:20
An example Wordpress (4.7+) plugin to create custom post types with custom taxonomies and custom meta fields, including exposing these to the REST API and adding custom columns in admin.
<?php
/**
* Plugin Name: Custom Post Types Example
* Description: An example plugin to create custom post types with custom taxonomies and custom meta fields, including exposing to the REST API.
* Plugin URI: http://kosso.co.uk
* Version: 1.0.0
* Author: Kosso
* Author URI: http://kosso.co.uk
* License: GPLv2
* Network: true
@kosso
kosso / block_from_timestamp.js
Created January 18, 2024 02:17
Get the Ethereum block number at a given date.
const axios = require('axios');
const SUBGRAPH_ETH_BLOCKS = 'https://api.thegraph.com/subgraphs/name/blocklytics/ethereum-blocks';
// Run: `node getBlockFromtimeStamp.js` to see the block number at the given date.
const date = 'Fri Dec 24 2021 10:22:12 GMT'; // The date you want to get the block number from.
const timestamp = Math.round(new Date(date).getTime() / 1000); // Unix timestamp in seconds
getBlockFromTimestamp(timestamp).then(block => {
// result
@kosso
kosso / background.html
Created March 2, 2012 13:40 — forked from mohamedmansour/background.html
Google Chrome Extension to upload a locally stored image to imgurl API service.
<!DOCTYPE html>
<html>
<head>
<script>
const API_KEY = 'SOME_KEY';
/**
* Use HTML5 Canvas to get the image data
* @param {HTMLImageElement} img An Image Tag
@kosso
kosso / gist:a513135384d5d78247f1af8464917a4c
Last active June 25, 2023 15:27
Instructions for setting up a Raspberry Pi Zero to send an iOS push notification when network interfaces go 'up'
###Sending Push notifications from Raspberry Pi when network interfaces go online.
- @kosso
- Apple : Set up app ID with Push Notifications cert.
- Download the .p12 CERT and KEY files
via: http://blog.raminrakhamimov.com/?p=81
Convert the p12 files to PEM format with:
@kosso
kosso / websocket-relay-secure.js
Created September 2, 2018 16:04
websocket-relay.js from JSMpeg slightly modified to use HTTPS instead of HTTP
// Use the websocket-relay to serve a raw MPEG-TS over WebSockets. You can use
// ffmpeg to feed the relay. ffmpeg -> websocket-relay -> browser
// Example:
// node websocket-relay yoursecret 8081 8082
// ffmpeg -i <some input> -f mpegts https://localhost:8081/yoursecret
var fs = require('fs'),
https = require('https'),
WebSocket = require('ws');
@kosso
kosso / dataURItoBlob
Created December 9, 2012 20:26
convert base64 to raw binary data held in a string
/**
via http://stackoverflow.com/questions/4998908/convert-data-uri-to-file-then-append-to-formdata/5100158
via http://www.smartjava.org/content/face-detection-using-html5-javascript-webrtc-websockets-jetty-and-javacvopencv
**/
function dataURItoBlob(dataURI) {
var binary = atob(dataURI.split(',')[1]);
var array = [];
for(var i = 0; i < binary.length; i++) {
@kosso
kosso / gist:02d602f7a6335c5bb1053efe1fa4b849
Created June 2, 2016 15:06
FFMPEG resize to 720p command
ffmpeg -i INPUT.mp4 -vf scale=-1:720 -c:v libx264 -crf 18 -preset veryslow -c:a copy OUTPUT.mp4
@kosso
kosso / WP_API_OAuth_Test_client.php
Last active September 16, 2021 05:30
Test PHP client for Wordpress REST API v2.0 / OAuth1.0a 0.3.0
<?php
//opcache_reset(); // Disable local dev MAMP cache
/*
WP_API_OAuth_Test_client.php
Tested with Wordpress 4.7.1
WordPress REST API - OAuth 1.0a Server v.0.3.0 - https://en-gb.wordpress.org/plugins/rest-api-oauth1/
@kosso
kosso / elasticsearch_7.4.0_on_RPi4
Created August 8, 2021 22:09
Setting up ElasticSearch 7.4.0 on a Raspberry Pi 4
Setting up ElasticSearch 7.4.0 on Raspberry Pi 4
================================================
sudo apt-get install default-jre
sudo nano /etc/profile
export JAVA_HOME=/usr/lib/jvm/default-java export PATH=$JAVA_HOME/bin:$PATH
sudo reboot
@kosso
kosso / index.php
Created October 17, 2019 16:19
Proxy script for Shoutcast audio streams.
<?php
// Proxy script for Shoutcast audio streams.
// Overcomes the CORS issue when using JavaScript to fetch streams for playback and analysis.
// Also http > https
/*
// .htaccess file
// eg: index.php and .htaccess in /radio on your host.
// Point JS/fetch to https://yourhost/radio/audio.mp3 (or any made-up .mp3 name)