Skip to content

Instantly share code, notes, and snippets.

View tim545's full-sized avatar

Tim tim545

  • Australia
View GitHub Profile
@tim545
tim545 / gist:1e10d066eeec6694ea08a1322f857f00
Created September 14, 2017 00:06 — forked from philfreo/gist:0a4d899de4257e08a000
4 different ways to save a Highcharts chart as a PNG (with and without a server)
// Method 1: simply use Highcharts built-in functionality (SVG -> Highcharts server -> PNG)
// Downside: won't work in webview native apps that don't handle the form response
highcharts.exportChart({
filename: filename
});
@tim545
tim545 / lg-jquery-app-struct.md
Last active March 11, 2024 18:59
Structuring a large jQuery application

Structuring a large jQuery application

This document assumes you are building a traditional backend-heavy application as opposed to a frontend-heavy appliction which would typically use a framework like Angular or React. The use of these frameworks make this document irrelevant, however also require a change to your application architecture and a much larger overhead in order to get content onto a page, so as a simple way to build interactive web content a simple jquery based js stack will do fine.

Directory structure

It's important you use a directory structure which is impartial to your development environment, chosen server language (Python v. Java v. C# ...), and styling framwork (Twitter Bootstrap etc). This layer of separation means you can swap out the styles or the backend with minimal changes to the Js, simple and maintainable.

Here's an example from the project root:

@tim545
tim545 / working-with-docker.md
Last active June 14, 2016 10:27
Working with Docker

Working with Docker

Although Docker has a huge learning curve, it also has a rewarding goal. Once you understand the docker way, things which were previously a blocker to your development can be done surprisingly easily.

Your production environment becomes the same as your development environment, making deployments simple.

Keeping your dev machine clean of muliple language dependencies also becomes a reality.

Difficult concepts

@tim545
tim545 / randomArrayItem.js
Last active December 11, 2015 05:44
Add a method to the Array prototype to return a random array item
// Adds a method to the Array prototype to return a random array item
Array.prototype.random = function() {
return this[Math.floor(Math.random() * this.length)];
};
@tim545
tim545 / node-setup.md
Last active May 9, 2016 23:10
Set up a dev machine to work on NodeJs projects
@tim545
tim545 / zerowidthspace.md
Last active August 11, 2019 14:51
The most evil character in Unicode

'Zero Width Space' character

I had some trouble with this character in a client project, it was hidden inside a configuration string which is validated in the clients API. It's basically invisible, literally a space character with zero width, it could not be seen but it was breaking at the API because it would not validate, causing problems with hundreds of user accounts.

The Unicode value of this character is U+200B, and it's evil, very evil. Lying in wait to break your applications while leaving no sign of it's presence...

It also has some friends, check the answer of this Stack Overflow question

In my project, it was one of my colleuges who managed to find the character, he re-copied the string into the code and Git showed that the line had been changed, even though all the Git GUI's didn't actually show any difference. He ran git diff in the command line and this did show the Unicode character being deleted, that's somet

Detect a mobile device in Javascript

This function will return true for any mobile device and false if not mobile.

//initiate as false
var isMobile = false;

// device detection
@tim545
tim545 / json2.js
Created July 28, 2015 05:03
JSON 2 JS converter, theoretically....
"object" != typeof JSON && (JSON = {}),
function() {
"use strict";
function f(t) {
return 10 > t ? "0" + t : t
}
function quote(t) {
return escapable.lastIndex = 0, escapable.test(t) ? '"' + t.replace(escapable, function(t) {
@tim545
tim545 / tech-reads.md
Last active March 15, 2018 23:02
Good technical articles

Good Technical Articles

This is a running list (in no particular order) of good articles/posts/tutorials I find on the web. I have tried to keep it narrowed down to articles which are in a sense 'timeless' in that they don't just teach something about a particular framework but also have something to be learnt about programming in general.

Conventions

@tim545
tim545 / New dev machine setup (Mac).md
Last active October 14, 2015 23:12
New development machine setup (Mac)

New development machine setup (Mac)

An attempt to store the steps for setting up a mac from scratch for web development. (Excluding any language-spcefic dependencies, for example Node.js or Ruby would not be listed here). Also note that this list only uses open source software, so replace anything with a paid alternative if appropriate.

These should be done in order:

Show hidden files by default

  • open Terminal and run defaults write com.apple.finder AppleShowAllFiles TRUE && killall Finder