Skip to content

Instantly share code, notes, and snippets.

View reggie3's full-sized avatar

Reginald Johnson reggie3

View GitHub Profile
var perms = [];
function permAlone(str) {
var strArr = str.split("");
//console.log(strArr);
// empty the answer array each time this function is called
perms = [];
permutator(strArr.length, strArr);
console.log(str + " - num perms: " + perms.length);
// console.log(perms.join(", "));
@reggie3
reggie3 / MapScreen.js
Created July 6, 2017 22:48
MapScreen for geofence-test application
class MapScreen extends Component {
constructor(props) {
super(props);
this.state = {
showNamePrompt: false,
location: undefined,
name: undefined
};
}
@reggie3
reggie3 / locationCheck.js
Created July 13, 2017 05:28
Calling location periodically
componentWillMount() {
...
// periodically check device location and write the results to
// the location markers
setInterval(
this.performLocationChecking.bind(this),
1000);
}
performLocationChecking() {
@reggie3
reggie3 / writeDistanceResults.js
Created July 13, 2017 05:32
Write distance results
case 'WRITE_DISTANCE_RESULTS':
return locations.map((location) => {
if (location.ID === action.ID) {
let distances = [action.distance].concat(location.distances);
distances = distances.slice(0, action.locationArrayMaxLength);
let distanceAverage = distances.reduce(function (sum, value) {
return sum + value;
}, 0) / distances.length;
return Object.assign({},
location,
@reggie3
reggie3 / monsterMarker.js
Created July 13, 2017 06:17
Monster Map Marker
<Expo.MapView.Marker
key={this.props.key}
image={this.state.sprites[this.state.imageCounter % 3]}
coordinate={{
latitude: this.props.location.loc[0],
longitude: this.props.location.loc[1],
}}
/>
componentDidMount = () => {
this.animationLooper();
}
animationLooper = () => {
this.setState({
imageCounter: this.state.imageCounter + 1
});
setTimeout(
this.animationLooper.bind(this),
const monster1 = require('../assets/sprites/monster/monster_walk01.png')
const monster2 = require('../assets/sprites/monster/monster_walk02.png')
const monster3 = require('../assets/sprites/monster/monster_walk03.png')
class LocationMarker extends Component {
constructor(props) {
super(props);
this.state = {
imageCounter: 0,
componentWillReceiveProps(nextProps) {
if (nextProps.location.distanceAverage < 10) {
this.setState({ loopSpeed: 10 });
}
else if (nextProps.location.distanceAverage < 100) {
this.setState({ loopSpeed: 100 });
}
else if (nextProps.location.distanceAverage < 1000) {
this.setState({ loopSpeed: 500 });
}
componentDidMount = () => {
let animation = this.requestAnimationFrame(this.animationLooper.bind(this));
}
animationLooper = () => {
let now = Date.now();
let deltaTime = now - this.state.then;
// user distance = time * rate to determine the amount the marker should grow or shrink
let growth = deltaTime / 1000 * this.state.markerGrowthSpeed;
render() {
return (
<Expo.MapView.Marker
key={this.props.key}
coordinate={{
latitude: this.props.location.loc[0],
longitude: this.props.location.loc[1],
}}>
<FontAwesome