Skip to content

Instantly share code, notes, and snippets.

View fodra's full-sized avatar
🎯
Focusing

Andrew Artajos fodra

🎯
Focusing
  • Australia
View GitHub Profile
@fodra
fodra / package.json
Created November 15, 2017 05:58
Package.json boilerplate
{
"name": "module-name",
"version": "0.0.1",
"description": "Application Description",
"author": "Sports Performance Tracking Pty. Ltd. <[email protected]> (https://www.sportsperformancetracking.com)",
"contributors": [
"Andrew Artajos <[email protected]>"
],
"scripts": {
"test": "istanbul cover node_modules/jasmine/bin/jasmine.js",
@fodra
fodra / jasmine.json
Created November 15, 2017 22:53
Jasmine config to be put in spec/support folder in the project folder.
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
@fodra
fodra / javascript-encoding-types.md
Created November 15, 2017 23:45
This is a list of possible encoding type values for everything node/javascript.

Javascript encoding type values

The character encodings currently supported by Node.js include:

  • 'ascii' - For 7-bit ASCII data only. This encoding is fast and will strip the high bit if set.

  • 'utf8' - Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.

  • 'utf16le' - 2 or 4 bytes, little-endian encoded Unicode characters. Surrogate pairs (U+10000 to U+10FFFF) are supported.

@fodra
fodra / commandline.js
Created November 30, 2017 03:38
Sample usage of command-line-args and command-line-usage
const commandLineArgs = require("command-line-args");
const getUsage = require("command-line-usage");
const optionDefinitions = [
{ name: "folder", alias: "f", type: String },
{ name: "gpsfiles", alias: "g", multiple: true, defaultOption: true }
];
const sections = [
{
header: "Sportnut",
@fodra
fodra / electron-packager-extra-resource.md
Created December 18, 2017 06:29
Command to add extra resources in your electron app

This is the example usage of electron-packager that I never found online anywhere else.

To add resource.exe and resource2.dll in the resource folder when you create an installer, this is how you do it with the --extra-resource commandline switch.

--extra-resource

electron-packager . --overwrite --asar --extra-resource="resource1.exe" --extra-resource="resource2.dll" --platform=win32 --arch=ia32 --icon=./frontend/dist/assets/icon.ico --prune=true --out=./build --version-string.ProductName='Hot Pan de sal'

within the backend code you can refer to the files as:

@fodra
fodra / transaction-management-error.md
Created January 9, 2018 01:23
This post is a summary of the bug I fixed for our web app throwing "django.db.transaction.TransactionManagementError: This is forbidden when an 'atomic' block is active."

The convoluted stack trace looks like this.

Traceback

[07/Jan/2018 15:04:32] ERROR [rq.worker:757] django.db.transaction.TransactionManagementError: This is forbidden when an 'atomic' block is active.
Traceback (most recent call last):
File "/srv/gametraka_project_v3-master/apps/events/parse_gpx.py", line 174, in process_imu_data
records = create_imu_data(track, records)
File "/usr/lib/python3.6/contextlib.py", line 52, in inner

return func(*args, **kwds)

@fodra
fodra / deep_copy.js
Created January 26, 2018 11:55
This is how you perform a deep copy in javascript as discussed in the HN article: Deep-copying in JavaScript.
function deepCopy(obj) {
return new Promise(resolve => {
const {send, recv} = new MessageChannel();
recv.onmessage = ev => resolve(ev.data);
send.postMessage(obj);
});
}
const obj = /* object to copy */;
const clone = await deepCopy(obj);
@fodra
fodra / pgexercises-basic-notes.md
Last active February 20, 2018 11:28
Here are some of my notes to the answers in pgexercises

Basic

Retrieve everything from a table

select * from cd.facilities;

Retrieve specific columns from the table

select name, membercost from cd.facilities;

@fodra
fodra / pgexercises-joins-notes.md
Created February 7, 2018 11:26
All about joins in PostgreSQL.

Joins

Retrieve the start times of members' bookings

The main thing here is the bit where you rename the table to something shorter: cd.members > mem. However this site clearly doesn't do that.

The concept is simple enough, you just have to join two tables that are related via a foreign key. When you join them together, you get a more detailed row.

-- get the 10 most recent sold listings for the specific agency
SELECT id, status, sold_price, sold_date
FROM listings_listing
WHERE agency_id = '3ab9adc2-7fd2-4b24-8cd0-d0cc69270fbf' AND status = 'S'
ORDER BY sold_date DESC LIMIT 10;
-- modify the query set to a new date somewhere between now and four weeks ago
UPDATE listings_listing
SET sold_date = now(),
source_type = 'M'