Skip to content

Instantly share code, notes, and snippets.

View woganmay's full-sized avatar

Wogan May woganmay

View GitHub Profile
@woganmay
woganmay / listen.js
Created April 25, 2017 10:11
Subscribe to a Mastodon streaming URL with NodeJS
// npm install websocket
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();
client.on('connectFailed', function(error) {
console.log('Connect Error: ' + error.toString());
});
client.on('connect', function(connection) {
@woganmay
woganmay / download.php
Created April 23, 2017 19:42
PHP code for downloading an entire ATOM timeline
<?php
// composer require phpoffice/phpexcel
require 'vendor/autoload.php';
// Webfinger
$url = "https://wogan.im/@wogan";
/**
* Start Webfinger lookup
/*
* Instructions:
* Open Mastodon, hit F11 (or whatever brings up your console)
* Paste this and hit enter
* http://i.imgur.com/LtQ5Zk3.gifv
*/
$(function(){
// Fetch the Emojione clientside library
$.getScript("https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.7/lib/js/emojione.min.js");
@woganmay
woganmay / sample-mailable.php
Created February 19, 2017 07:30
Send basic templated email with Mailable
<?php
public function build()
{
return $this
->subject('Mail Subject')
->view('vendor.notifications.email')->with([
"level" => "default",
"greeting" => "Hi, User!",
"introLines" => [
@woganmay
woganmay / sample.php
Last active February 19, 2017 07:25
Sample MailMessage
<?php
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Mail Subject')
->greeting('Hi, User!')
->line('A line before the big button')
->action('Action Button', url('/'))
@woganmay
woganmay / upload-flarum-avatar.php
Created February 12, 2017 14:03
Upload a new avatar image to Flarum
<?php
// See: https://gist.github.com/woganmay/4c15a0f7c16e41ab3a3ea1a73c595bf9
$api_url = sprintf("https://my.flarum.site/api/users/%s/avatar", $user->id);
// See: https://gist.github.com/woganmay/88f15e96fc019657a0e594366403b5cf
$token = $session->token;
$avatar_file = "/storage/avatars/1234.jpg"; // Absolute path preferred
<?php
// See: https://gist.github.com/woganmay/4c15a0f7c16e41ab3a3ea1a73c595bf9
$api_url = sprintf("https://my.flarum.site/api/users/%s/avatar", $user->id);
// See: https://gist.github.com/woganmay/88f15e96fc019657a0e594366403b5cf
$token = $session->token;
$ch = curl_init($api_url);
@woganmay
woganmay / custom-header.html
Created February 12, 2017 13:59
Modify the Flarum UI
<script type="text/javascript">
var thisHackInterval = setInterval(function(){
// Check if app is available yet
if (typeof(app) == "object")
{
// Set app routes to whatever I need
// This will repaint the DOM automatically
app.routes.settings.path = "https://my.laravel.site/preferences";
@woganmay
woganmay / index.php
Created February 12, 2017 13:56
Check for Flarum authentication before the main site even loads
<?php
if (isset($_COOKIE['flarum_remember']))
{
$mysql = new mysqli("localhost", "flarum_sql_user", "flarum_sql_pass", "flarum_database");
$result = $mysql->query("SELECT * FROM access_tokens WHERE id = '". $mysql->real_escape_string($_COOKIE['flarum_remember']) ."'");
if ($result->num_rows == 0)
{
// Invalid cookie
header('Location:https://my.laravel.site/login');
@woganmay
woganmay / set-flarum-cookie.php
Created February 12, 2017 13:54
Set the flarum_remember cookie from a GET parameter