Skip to content

Instantly share code, notes, and snippets.

@ncole458
ncole458 / haversine.py
Last active November 8, 2023 00:07
Django Haversine Formula Queryset
"""
Find user/database entries within a km radius based on long/lat co-ords.
i.e. return all objects where longlat lies within 10km of my current long/lat.
Using with Django REST Framework but approach is same for any similar req.
"""
import math
def get_queryset(self):
user = self.request.user
lat = self.request.query_params.get('lat', None)
@ncole458
ncole458 / distance.py
Last active March 8, 2023 10:11
Django queryset for objects within X long/lat radius
# Simple version of Django queryset for objects within X long/lat radius
import math
def get_queryset(self):
user = self.request.user
lat = self.request.query_params.get('lat', None)
lon = self.request.query_params.get('long', None)
if lat and lon:
lat = float(lat)
@ncole458
ncole458 / gist:8060b026b7f5075742d04fc192ad042e
Last active September 24, 2020 08:47
Fix React Native cache issues on Android
FIX CACHE ISSUES ON ANDROID – REACT NATIVE BUILD
cd android && cd app && rm -r build
cd android && ./gradlew clean
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
cd android &&chmod +x gradlew
@ncole458
ncole458 / WIP.txt
Created May 19, 2020 05:30
AWS CLI Cheatsheet
# Connect Multiple AWS Accounts
aws configure --profile <your-profile-name>
@ncole458
ncole458 / psql.md
Created September 15, 2019 04:28
PostgreSQL Cheatsheet

change to postgres user and open psql prompt

sudo -u postgres psql postgres

list databases

postgres=# \l

list roles

@ncole458
ncole458 / CronJobLeader.txt
Created January 22, 2020 10:11
AWS cron perms
# Inline policy for aws-elasticbeanstalk-ec2-role
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1409855610000",
"Effect": "Allow",
"Action": [
"autoscaling:DescribeAutoScalingGroups"
@ncole458
ncole458 / .gitignore
Created March 4, 2019 01:17
Python/Django .gitignore
### Virtualenv
venv/
### PyCharm
.idea/
### Python
__pycache__/
*.py[cod]
@ncole458
ncole458 / encode_test.py
Created January 14, 2019 02:53
Python Encode
# test .encode() and str()
a_string = 'test éurope'
print('a_string normal: ', a_string)
a_string = 'test éurope'
print('a_string utf-8 encoded: ', a_string.encode('utf-8')) # utf-8 is default so .encode() is same result
print('a_string ascii encoded: ', a_string.encode('ascii', 'replace')) # with error, i.e. replace, ignore etc.
print('a_string str: ', str(a_string))
company = 'éuropean company'
pro_comp_name = 'a løng campaigné name'
@ncole458
ncole458 / Ember.js
Created October 18, 2018 10:42
Ember.js fix node/bower cache issues
# sometimes Ember builds break due to npm &/or bower cache, node changes etc.
# running below usually fixing any cache issues
rm -rf node_modules/ bower_components/ tmp/ dist/
npm cache clear
bower cache clear
npm install && bower install
ember s
@ncole458
ncole458 / docker.txt
Last active October 15, 2018 03:21
Docker commands
# view container instances
docker container ls
# activate instance, i.e. nginx, django etc.
docker exec -i -t be821b60fa28 /bin/bash