Skip to content

Instantly share code, notes, and snippets.

View ericjames's full-sized avatar

Eric James ericjames

View GitHub Profile
@ericjames
ericjames / git-fix-author-email.md
Created November 30, 2022 03:21
Fix author and email of all git commits

git rebase -i --root -x "git commit --amend --reset-author -CHEAD"

@ericjames
ericjames / mapbox-filter-examples
Last active October 31, 2021 16:06
Mapbox Filter Examples
// Toggling the 'feature-state' boolean via map.setFeatureState
'line-width': [
'case',
['boolean', ['feature-state', 'hover'], false],
10,
2
]
@ericjames
ericjames / mapbox-addsource-edit
Created October 30, 2021 17:11
Mapbox: Edit new source data on the fly
// You can edit source data on the fly but it requires it to have a layer first, as there is no way to directly access GeoJSON
// GeoJson is only exposed via querySourceFeatures, grabbing features from a map's layer
const yourSourceId = 'some-source';
const url = 'some-url';
map.addSource(yourSourceId, {
type: 'geojson',
data: url
@ericjames
ericjames / reactnative-fitCardInView.js
Last active April 5, 2019 18:24
React Native attempt to reposition a View ("Card") in the scrollview if it goes out of bounds
//Adjust the scroll if we think the card content is going out of viewable bounds
fitCardInView = () => {
this.props.setAnimatingMap(true);
if (!this.cardView || !this.cardView.measureInWindow) {
return false;
}
this.cardView.measureInWindow((x, y, width, height) => {
// console.log(this.layout.height, y);
@ericjames
ericjames / SetWebView.kt
Created October 22, 2018 18:32
Android Kotlin: Set a WebView
val webView = findViewById<WebView>(R.id.tosWebView)
webView.visibility = 1
webView.webViewClient = WebViewClient()
webView.settings.javaScriptEnabled = true
webView.settings.domStorageEnabled = true
webView.overScrollMode = WebView.OVER_SCROLL_NEVER
webView.loadUrl(R.string.tos_url.toString())
@ericjames
ericjames / ReactNative-WebView.js
Created May 21, 2018 19:03
React-Native WebView Example
this.setState({
webViewUri: "https://transitscreen.com/termsofuse",
webViewDisplay: "flex"
});
<WebView
source={{uri:this.state.webViewUri}}
style={{height:400, width: 380, flex: 2, display: this.state.webViewDisplay}}
onError={console.error.bind(console, 'error')}
bounces={false}
@ericjames
ericjames / mapbox-polyline-geojson.js
Last active April 11, 2018 17:38
Google Maps Polyline Encoding to GeoJSON coordinates for Mapbox integration (Credit to @ivansams)
// Obtained from https://github.com/ivansams at https://jsfiddle.net/ivansams/tw7qLvh4/2/
// Only the function that converts polyline to geojson coordinates for Mapbox integration
// Was previously called GetGeoJSON, but this function simply returns a flat array of polylines in [lng, lat] format
function getCoordsFromPolyline(str, precision) {
var precision = precision || 5; // Precision as 5 yields 00.000
var index = 0,
lat = 0,
lng = 0,
coordinates = [],
@ericjames
ericjames / parsehours.php
Created March 12, 2018 17:42
Parse Hours in PHP
<?php
function parseHours($value) {
$hours = json_decode($value);
$hours = (array)$hours;
foreach ($hours as $day => $hourstring) {
$time = explode("-", $hourstring);
$time[0] = trim(str_replace(' ', '', $time[0]));
if (isset($time[1])) {
@ericjames
ericjames / swift3-logging-uitextview.swift
Created November 18, 2017 21:40
Swift 3 - Using a UITextView as a console log
func log(text: String, pauseLog: Bool) {
let newDate = Date()
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US")
dateFormatter.setLocalizedDateFormatFromTemplate("HH:mm:ss")
let displayDate = dateFormatter.string(from: newDate) + ": "
let newLogText = (self.outputText.text ?? "\n") + displayDate + text + "\n"
print(newLogText)
@ericjames
ericjames / swift4-uipickerview-example.swift
Created November 13, 2017 21:35
Swift 4 - UIPickerView
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerDataSource.count;
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerDataSource[row]