Skip to content

Instantly share code, notes, and snippets.

View akanik's full-sized avatar

Alexandra Kanik akanik

View GitHub Profile
@akanik
akanik / query_run_time
Created July 7, 2017 19:00
How long a process takes
#https://stackoverflow.com/questions/1345827/how-do-i-find-the-time-difference-between-two-datetime-objects-in-python
>>> import datetime
>>> a = datetime.datetime.now()
>>> b = datetime.datetime.now()
>>> c = b - a
datetime.timedelta(0, 8, 562000)
>>> divmod(c.days * 86400 + c.seconds, 60)
(0, 8) # 0 minutes, 8 seconds
@akanik
akanik / terminal-video-to-gif
Last active January 25, 2023 19:04
video to animated gif
#https://github.com/skepticli/tutorial-screencast-to-gif
#command line
mkdir frames
ffmpeg -i my-screencast.mov -r 3 frames/image.%03d.png
#At this point it might be useful to go into your frames
#directory and delete extra images, most likely frames at
#the start and end of your video/gif
@akanik
akanik / QGIS_leading_0
Created June 22, 2017 16:54
Add leading zero(s) to FIPS codes in QGIS
#county
right( ('000' || tostring( "myfield" )), 4)
#state
right( ('0' || tostring( "fips" )), 2)
@akanik
akanik / QGIS_NULL_to_0
Created June 22, 2017 16:51
Turn layer attribute table values from NULL into 0 for styling
case when "Some_Value" IS NULL then 0 else "Some_Value" end
@akanik
akanik / wav-mp3-ffmpeg
Created April 27, 2017 13:48
WAV to MP3 with ffmpeg
ffmpeg -i CAPITOJINX.wav -f mp3 capitojinx.mp3
@akanik
akanik / arc-gov-appal-counties.csv
Created July 18, 2016 21:12
A csv list of counties considered "Appalachian" by arc.gov.
state county
Alabama Bibb
Alabama Blount
Alabama Calhoun
Alabama Chambers
Alabama Cherokee
Alabama Chilton
Alabama Clay
Alabama Cleburne
Alabama Colbert
@akanik
akanik / logging.py
Created March 18, 2016 03:28
logging text and Exception
from sys import argv
import datetime, os, logging
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
def handle(self, *args, **options):
self.print_date()
def print_date(self):
@akanik
akanik / excel-csv.py
Last active May 15, 2018 15:26
excel sheets to individual csv files
# Thanks to http://stackoverflow.com/questions/9884353/xls-to-csv-convertor
import os, csv, xlrd
excel_file = '/path/to/file.xls'
#we're specifying a directory here because we'll have several files
#be sure to include end slash
csv_filepath = 'path/to/csv/directory/'
def csv_from_excel(excel_file):
workbook = xlrd.open_workbook(excel_file)
@akanik
akanik / htaccess-modrewrite.txt
Created February 2, 2016 21:42
turn modrewrite on
RewriteEngine on
@akanik
akanik / htaccess-no-naked.txt
Created February 2, 2016 20:34
htaccess redirect naked domain
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# Make sure to replace example.com with your own site name
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]