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
@joduplessis
joduplessis / self-driving-car-unity.cs
Created September 4, 2017 19:40
Strategy for implementing self driving cars (objects) in Unity 3D. This is very taxing on the CPU as it essentially uses computer vision in the game world sense.
RaycastHit hit;
bool foundRoad = false;
bool playerIsInFront = false;
Vector3 current = new Vector3(gameObject.transform.position.x, 5, gameObject.transform.position.z);
Vector3 aheadWorld = new Vector3(0, -5, 15);
Vector3 leftWorld = new Vector3(-15, -5, 0);
Vector3 rightWorld = new Vector3(15, -5, 0);
Vector3 behindWorld = new Vector3(0, -5, -15);
@joduplessis
joduplessis / sequences.php
Created September 4, 2017 19:42
The very famous sequenced printout test people like to ask for when interviewing junior devs.
<?php
for ( $x=1 ; $x<=100 ; $x++ ) {
if ( ( fmod($x,3) == 0 ) && ( fmod($x,7) == 0 ) ) {
echo "<span style='color:#ff0000'>Both</span><br/>" ;
} else if ( fmod($x,3) == 0 ) {
echo "<span style='color:#00ff00'>Three</span><br/>" ;
} else if ( fmod($x,7) == 0 ) {
echo "<span style='color:#0000ff'>Seven</span><br/>" ;
} else {
echo $x . "<br/>" ;
@joduplessis
joduplessis / todo-material-layout.html
Created September 4, 2017 19:56
Page layout for replicating a Wunderlist type of app using the Google Material components. This is only the layout.
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:300,400,500,700" type="text/css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Work+Sans:400,100,200,300,500,600,700,800,900" type="text/css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Arvo:400,400italic,700,700italic" type="text/css" />
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.blue_grey-amber.min.css" />
<style>
@joduplessis
joduplessis / firebase.storage.js
Created September 5, 2017 08:04
Add images to Google Cloud Storage (inc. Firebase) using NodeJS.
/*
* Example for adding images to Google Cloud Storage using NodeJS.
* This integrates with Firebase, you just need to download the keyfile.
* Firebase project > Settings > Firebase Admin SDK > Generate new private key.
* Don't forget to install dependancies: "yarn add bluebird @google-cloud/storage"
*/
const projectId = 'xxx'
const bucketName = projectId+'.appspot.com'
const Promise = require('bluebird');
const GoogleCloudStorage = Promise.promisifyAll(require('@google-cloud/storage'));
@joduplessis
joduplessis / async-redux.js
Last active September 7, 2017 08:29
Example of handling React Native's AsyncStorage with Redux actions.
import { AsyncStorage } from 'react-native';
export const actionMethod = () => {
return (dispatch, getState) => {
(async () => {
try {
const value = await AsyncStorage.setItem('@YourStore:key', '12345');
if (value !== null) {
// Value of the stored token
@joduplessis
joduplessis / command-line-input.js
Created September 11, 2017 14:23
Node boilerplate/example for receiving input from the console in a recursive manner.
#! /usr/bin/env node
// Resume our input from the console
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Receive some data
process.stdin.on('data', function (text) {
// Split the string arguments
const receivedInputArguments = text.replace(/\n$/, '').split(' ');
@joduplessis
joduplessis / random-number-csv.js
Created September 11, 2017 15:02
Generate random numbers that are unique and writing that to a CSV document.
/*
* System for generating x number of unique numbers and writing that to a CSV
* document. Good for competitions or anything requiring true unique numbers.
* Also an interesting exercise for Node/Javascript perf.
*/
const fs = require('fs');
const numbers = [];
const start = 111111111; // We don't want any leading 0's
const end = 999999999;
const amount = 3000000;
@joduplessis
joduplessis / index.tsx
Created September 11, 2017 21:21
Example Rollup config file for building React components using Typescript.
import React from 'react';
import * as ReactDOM from 'react-dom';
export default class HQueue extends React.Component<any, any> {
constructor(props: any) {
super(props);
}
public componentDidMount() {
}
@joduplessis
joduplessis / cookie-typescript-utils.ts
Created September 12, 2017 06:50
Setting, deleting and retrieving cookies in Typescript.
@joduplessis
joduplessis / rn-async-webapi.js
Created September 13, 2017 13:05
Example of making an async React Native call to a .NET Web API 2 project.
/*
* Example of making an async React Native call to a .NET Web API 2 project.
* Helped with this issue a few times now.. Note the content type.
*/
(async () => {
// Make the API call
fetch(constants.API_ROUTE+'Token', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},