Skip to content

Instantly share code, notes, and snippets.

View smks's full-sized avatar

Shaun Stone smks

View GitHub Profile
@smks
smks / JoystickControls.hx
Created August 26, 2015 19:14
JoystickControls.hx
package smks.controls;
import flixel.ui.FlxAnalog;
import smks.player.Player;
/**
* @author Shaun Stone (SMKS) <shaunmstone@gmail.com>
* @shaunmstone
*/
class JoystickControls
{
@smks
smks / Confetti.hx
Last active March 1, 2023 02:32
Haxeflixel Confetti Example
package com.particles;
import flixel.effects.particles.FlxEmitter;
import flixel.effects.particles.FlxParticle;
import flixel.FlxG;
import flixel.group.FlxTypedGroup;
import flixel.system.FlxCollisionType;
import flixel.util.FlxRandom;
/**
@smks
smks / fetch.js
Created November 12, 2016 11:48
How to Code - JavaScript Fetch
fetch('http://opencanvas.co.uk/ocl/api/actors?date=12-11-2016')
.then(function(res) {
return res.json();
})
.then(function(json) {
console.log(json);
});
@smks
smks / expenses.js
Last active November 13, 2016 13:21
Example of chaining multiple promises
const monthlyRent = 600;
const monthlyFoodCosts = 420.5;
const monthlyElectricBill = 45;
const monthlyGymMemberShip = 38;
const monthlySpotifyMemberShip = 15;
let costsOutstanding = 1118.5;
const payExpense = (expenseAmount) => {
return new Promise((resolve, reject) => {
@smks
smks / fruits.js
Last active November 13, 2016 13:20
Use of Constant and Let
// this has to be today's date.
const dateToday = '12-11-2016';
fetch('http://opencanvas.co.uk/ocl/api/fruits?date=' + dateToday)
.then(function(res) {
return res.json();
})
.then(function(json) {
const fruits = json.fruits;
for (let index in fruits) {
@smks
smks / intl.js
Created November 12, 2016 19:07
Features of the Intl API
// Number Formatter
var communityPoints = 35000000.00;
var ukFormatter = new Intl.NumberFormat('en-uk');
var formattedNumber = ukFormatter.format(communityPoints);
console.log(formattedNumber);
// Currency formatter
var houseMaterialCosts = 120457.46;
var currencyFormatter = new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'GBP' });
var formattedCosts = currencyFormatter.format(houseMaterialCosts);
var formElement = document.createElement('form');
formElement.setAttribute('method','post');
formElement.setAttribute('action','login.php');
var usernameField = document.createElement('input');
usernameField.setAttribute('type','text');
usernameField.setAttribute('name','username');
var passwordField = document.createElement('input');
passwordField.setAttribute('type','password');
@smks
smks / bind.js
Created November 13, 2016 13:00
Demonstration of how bind() works in JavaScript
/**
*
* Incorrect Context
*
*/
class Greeter {
constructor(name) {
this.name = name;
}
const batman = {firstName: 'Bruce', lastName: 'Wayne'};
const superman = {firstName: 'Clark', lastName: 'Kent'};
function speak(quote, location) {
console.log(this);
console.log(this.firstName + ' ' + this.lastName + ' ' + 'says ' + quote + ' from ' + location);
};
// Apply for Array
speak.apply(batman, ["'It's not who I am underneath, but what I do that defines me'", "Gotham City"]);
@smks
smks / mason.js
Last active June 10, 2020 18:30
This is a sample commander CLI application used in Medium Article - How I automated my Job with Node JS
#! /usr/bin/env node
const mason = require('commander');
const { version } = require('./package.json');
const console = require('console');
// commands
const create = require('./commands/create');
const setup = require('./commands/setup');