Skip to content

Instantly share code, notes, and snippets.

View tyler-austin's full-sized avatar

Tyler Austin tyler-austin

  • Scale AI
  • Washington DC
  • 21:45 (UTC -04:00)
View GitHub Profile
@tyler-austin
tyler-austin / JSZip-images.js
Last active July 21, 2022 11:31
JSZip Open image files
// https://github.com/Stuk/jszip/issues/399
JSZip.loadAsync(data).then(function (zip) {
var re = /(.jpg|.png|.gif|.ps|.jpeg)$/;
var promises = Object.keys(zip.files).filter(function (fileName) {
// don't consider non image files
return re.test(fileName.toLowerCase());
}).map(function (fileName) {
var file = zip.files[fileName];
return file.async("blob").then(function (blob) {
@tyler-austin
tyler-austin / README.md
Created May 31, 2017 22:02
Code Fights - commonCharacterCount

Given two strings, find the number of common characters between them.

Example

For s1 = "aabcc" and s2 = "adcaa", the output should be
commonCharacterCount(s1, s2) = 3.

Strings have 3 common characters - 2 "a"s and 1 "c".

Input/Output

@tyler-austin
tyler-austin / numberOfCharInString.js
Created March 25, 2019 19:29
[JavaScript] Number of Occurances of a Character in a String
const numberOfCharInString = (c, s) => {
let [count, index] = [0, 0];
while (true) {
index = s.indexOf(c, index);
if (index >= 0) {
++count;
++index;
} else break;
}
return count;
@tyler-austin
tyler-austin / cSharp.py
Created April 16, 2018 13:10
C# Tutorials
# https://www.tutorialspoint.com/csharp/index.htm
# https://www.dotnetperls.com/
@tyler-austin
tyler-austin / grass-viewshed.py
Last active April 14, 2018 20:04
Grass Viewshed calculation
import grass.script as grass
grass.run_command('r.viewshed',
input='standard.dem',
output='viewshed',
coordinate=[observer_x, observer_y],
obs_elev=1.75,
tgt_elev=0.0,
memory=4098,
overwrite=True,
@tyler-austin
tyler-austin / README.md
Last active January 9, 2018 06:23
Code Fights - areSimilar

Two arrays are called similar if one can be obtained from another by swapping at most one pair of elements in one of the arrays.

Given two arrays a and b, check whether they are similar.

Example

For a = [1, 2, 3] and b = [1, 2, 3], the output should be
areSimilar(a, b) = true.

The arrays are equal, no need to swap any elements.

@tyler-austin
tyler-austin / arcpy_field_names.py
Created May 30, 2017 20:56
arcpy field names
import arcpy
vector_file = os.path.join(r"/path/to/feature/class")
field_names = [f.name for f in arcpy.ListFields(vector_file)]
field_names
# [u'FID', u'Shape', u'Id']
<!DOCTYPE html>
<html>
<head>
<title>Previous/Next Extent</title>
<meta charset="utf-8">
<link rel="stylesheet" href="//js.arcgis.com/3.21/esri/css/esri.css">
<style>
html, body {
margin: 0; padding: 0;
width: 100%; height: 100%;
@tyler-austin
tyler-austin / README.md
Created June 21, 2017 19:10
Code Fights - differentSymbolsNaive

Given a string, find the number of different characters in it.

Example

For s = "cabca", the output should be
differentSymbolsNaive(s) = 3.

There are 3 different characters a, b and c.

Input/Output

@tyler-austin
tyler-austin / README.md
Created June 21, 2017 18:59
Code Fights - firstDigit

Find the leftmost digit that occurs in a given string.

Example

  • For inputString = "var_1__Int", the output should be
    firstDigit(inputString) = '1';
  • For inputString = "q2q-q", the output should be
    firstDigit(inputString) = '2';
  • For inputString = "0ss", the output should be
    firstDigit(inputString) = '0'.