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 / image-upload-react-native.js
Created September 19, 2017 13:28
Simple example of uploading an image taken with a camera with React Native & Expo
takePicture = async () => {
let result = await ImagePicker.launchCameraAsync({
allowsEditing: true,
aspect: [4, 3],
});
if (!result.cancelled) {
// Probably not all necessary, but good to have to do stuff with
const context = this;
const file = result.uri;
@joduplessis
joduplessis / messenger-code-generation.js
Created September 26, 2017 12:02
Using Request to generate Facebook messenger codes
/*
* Using Request to generate Facebook messenger codes
*/
const request = require('request');
const token = 'FB_TOKEN';
// Request options (pretty standard)
const options = {
url: 'https://graph.facebook.com/v2.6/me/messenger_codes?access_token='+token,
method: 'POST',
@joduplessis
joduplessis / lat-lng.js
Last active October 13, 2017 07:13
Calculate the distance between 2 lat/lng positions
/*
* Calculates the distance between 2 lat/lng points provided as decimals.
* Can be used with copy & pasted values in Google Maps.
*/
calculateDistance(lat1, lon1, lat2, lon2) {
const theta = lon1 - lon2;
const unit = "K"; // kilometer
// Do the sin/cos calculation
let dist = Math.sin(this.deg2rad(lat1)) * Math.sin(this.deg2rad(lat2)) + Math.cos(this.deg2rad(lat1)) * Math.cos(this.deg2rad(lat2)) * Math.cos(this.deg2rad(theta));
@joduplessis
joduplessis / lat-lng-java.java
Created October 13, 2017 07:48
Getting the distance between 2 lat/lng position in Java
/*
* Getting the distance between 2 lat/lng position in Java
*/
private double distance(double lat1, double lon1, double lat2, double lon2, char unit) {
double theta = lon1 - lon2;
double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
dist = Math.acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515;
@joduplessis
joduplessis / unique_numbers.py
Created December 17, 2017 11:15
Simple script for generating a set amount of unique random numbers in Python.
from random import randint
import math
numbers = []
start = 111111111
end = 999999999
amount = 4000000
ticker = 0
step = math.floor((end - start) / amount)
thefile = open('newnumbers.csv', 'w')
@joduplessis
joduplessis / svg_id.py
Created December 17, 2017 11:18
Add an auto incremented ID to each shape in an SVG file.
import string
svgFile = 'pattern.svg'
svgFileNew = 'pattern1.svg'
with open(svgFile) as f:
thefile = open(svgFileNew, 'w')
@joduplessis
joduplessis / svg-to-pdf.js
Created January 12, 2018 07:18
Basic NodeJS web service that converts an SVG file to a publicly accessible PDF file. Useful for on-the-fly conversions.
const fs = require('fs');
const PDFDocument = require('pdfkit');
const SVGtoPDF = require('svg-to-pdfkit');
const express = require('express');
const promise = require('bluebird');
const formidable = require('formidable');
const http = require('http');
const https = require('https');
const util = require('util');
const app = express();
@joduplessis
joduplessis / bitbucket-ftp-push.yml
Created March 6, 2018 06:41
Simple FTP push using BitBucket pipelines.
image: node:7.10.1
pipelines:
default:
- step:
script:
- node -v
- npm install
- apt-get update
- apt-get install -y lftp
- lftp -u USERNAME,PASSWORD FTPDOMAIN -e "mirror -e -R -p ./dist/ public_html ; quit"
@joduplessis
joduplessis / gitlab-ci.yml
Created March 6, 2018 06:42
Simple FTP push using GitLab CI.
image: node:7
before_script:
- npm install
- apt-get update
- apt-get install -y lftp
cache:
paths:
- node_modules/
@joduplessis
joduplessis / AppName.plist
Created March 9, 2018 11:02
Sample plist file for over-the-air deployment. Rererenced from another Gist, kept here for my reference.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>