Skip to content

Instantly share code, notes, and snippets.

View tyler-austin's full-sized avatar

Tyler Austin tyler-austin

  • Scale AI
  • Washington DC
  • 23:34 (UTC -04:00)
View GitHub Profile
@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 / 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 / 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,
<!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'.
@tyler-austin
tyler-austin / README.md
Created June 21, 2017 18:45
Code Fights - extractEachKth

Given array of integers, remove each kth element from it.

Example

For inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and k = 3, the output should be
extractEachKth(inputArray, k) = [1, 2, 4, 5, 7, 8, 10].

Input/Output

  • [time limit] 4000ms (py3)
@tyler-austin
tyler-austin / README.md
Created June 21, 2017 18:07
Code Fights - stringsRearrangement

Given an array of equal-length strings, check if it is possible to rearrange the strings in such a way that after the rearrangement the strings at consecutive positions would differ by exactly one character.

Example

  • For inputArray = ["aba", "bbb", "bab"], the output should be
    stringsRearrangement(inputArray) = false;

    All rearrangements don't satisfy the description condition.

  • For inputArray = ["ab", "bb", "aa"], the output should be

@tyler-austin
tyler-austin / README.md
Created June 19, 2017 17:46
Code Fights - absoluteValuesSumMinimization

Given a sorted array of integers a, find such an integer x that the value of

abs(a[0] - x) + abs(a[1] - x) + ... + abs(a[a.length - 1] - x)

is the smallest possible (here abs denotes the absolute value). If there are several possible answers, output the smallest one.

Example

For a = [2, 4, 7], the output should be