Skip to content

Instantly share code, notes, and snippets.

View joduplessis's full-sized avatar
Brewing coffee.

Jo du Plessis joduplessis

Brewing coffee.
View GitHub Profile
<?php
/*
* The following code illustrates how to use batch operations with the
* new Mailchimp v3 API. Much of what I found on the net was half baked
* and relied on another layer of abstraction.
*
*/
$subscribers = [];
$batch_operations = [];
/*
* Simple message relay server you could use for almost anything
* A popular specific use case is for chat/multiplayer games
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.*;
/*
* Very simple demo showing how to play videos
* using RawTexture and Unity 5.x UI
*
* Just a note - this is PC/OSX specific
*/
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
/*
* A simplistic chat relay server that pools client connections
* Written with Node, ES5 & using web sockets (Socket.io)
*/
var io = require("socket.io");
var socket = io.listen(8001);
var people = [];
// On connection start
@joduplessis
joduplessis / gist:4ddc18f708a28923fe26bbb65ee5fd93
Created June 26, 2017 10:33
.htaccess codes for redirecting to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@joduplessis
joduplessis / ng2-charts.dynamic-update.ts
Created September 4, 2017 16:43
Boilerplate for updating ng2-charts in Angular. This is in reference to a couple of bugs where changing data dynamically doesn't update the chart data. See more here https://github.com/valor-software/ng2-charts/issues/291
import { Component, SimpleChanges, ViewChildren } from '@angular/core';
import { BaseChartDirective } from 'ng2-charts/ng2-charts';
@Component({
selector: 'app',
template: '<canvas baseChart #chart
[chartType]="'line'"
[options]="chartOptions"
[labels]="chartLabels"
[colors]="chartColors"
@joduplessis
joduplessis / matter-circle.js
Created September 4, 2017 19:21
Example of using MatterJS to draw a cirlce on a canvas.
function init() {
// Matter.js module aliases
let Engine = Matter.Engine,
World = Matter.World,
Composites = Matter.Composites,
Bodies = Matter.Bodies;
// Particle options
let particleOptions = {
friction: 0.05,
@joduplessis
joduplessis / mutliplayer-dots.js
Last active September 5, 2017 20:19
Simplistic example showing multiplayer movement in the browser. This works off a simple websocket server.
"use strict" ;
function init() {
let socket = io('http://localhost:3000');
let div = document.createElement("div");
let top = 10 ;
let left = 10 ;
let movementIncrement = 5 ;
let randomNumber = Math.random() + "" ;
@joduplessis
joduplessis / scene-graph.js
Last active September 4, 2017 19:37
Test showing the use of a scene graph / canvas abstraction layer instead managing the canvas context directly.
function init() {
"use strict" ;
var canvas = document.getElementsByTagName("canvas")[0] ;
var context = canvas.getContext("2d") ;
var particles = [] ;
var width = 1024 ;
var height = 680 ;
@joduplessis
joduplessis / php-design-patterns.php
Created September 4, 2017 19:38
Design pattern examples using PHP. These are a bit dated, but hey. It's a gist.
<h1>Design Patterns</h1>
<h2>Singleton classes ( persist one object over multiple calls )</h2>
<?php
class Database
{