Skip to content

Instantly share code, notes, and snippets.

View palevell's full-sized avatar

Patrick Allan palevell

View GitHub Profile
@palevell
palevell / edsh
Created August 10, 2017 15:10
Edit BASH shell script
#!/usr/bin/env bash
# edsh v1.4.27 - March 3, 2014
_me="${0##*/}"
# Test for file name
[[ $# -ne 1 ]] && { echo -en "Usage:\t$_me command_name\n"; exit 1; }
_file=~/bin/$1
# If needed, create a new command file
if [[ ! -e $_file ]]; then
@palevell
palevell / t-clean.py
Last active October 9, 2017 15:34
Cleanup Twitter Followings with Ruby Gem 't' and Python's language detect module
#!/usr/bin/env python3
# t-clean.py v1.2.22 - Friday, September 15, 2017
# Cleanup Twitter Followings with Ruby Gem 't' and Python's language detect module
""""
Long Records (follow, unfollow, groupies, whoami, etc.)
0 ID
1 Since
2 Last tweeted at
3 Tweets
@palevell
palevell / sql-ins-upd-ignore.py
Last active October 17, 2018 23:04
This code snippet demonstrate's SQLite's new UPSERT command.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# sql-ins-upd-ignore.py v1.0.0 - Tuesday, October 16, 2018
# Ref1: https://stackoverflow.com/a/50718957/2719754
# Ref2: https://www.sqlite.org/lang_UPSERT.html
"""
The UPSERT command is implemented by way of an ON CONFLICT clause
on the INSERT statement.
@palevell
palevell / pelicanconf-themes.py
Last active January 15, 2022 21:07
This is an example Pelican config file for testing pelican-themes.Enjoy!
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
# 2019-Jun-19 PAL - This is for testing pelican-themes
from random import choice
import os, sys
sys.path.append(os.curdir)
# 2019-Jun-19 PAL - Load pelican-themes list (for testing)
from themes import Themes
@palevell
palevell / themes.py-sample.py
Created June 19, 2019 16:24
This is the list of pelican-themes at the time of this writing. To use it, place it in the same directory as your Pelican settings file (ie. `pelicanconf.py`) and rename it to `themes.py`.
# themes.py - Tuesday, June 18, 2019
""" This list is for testing pelican-themes """
Themes = [
'pelican-themes/smoothie', 'pelican-themes/water-iris',
'pelican-themes/voidy-bootstrap', 'pelican-themes/dev-random',
'pelican-themes/hyde', 'pelican-themes/lab',
'pelican-themes/Casper2Pelican', 'pelican-themes/basic',
'pelican-themes/dev-random2', 'pelican-themes/subtle',
'pelican-themes/Responsive-Pelican', 'pelican-themes/plumage',
@palevell
palevell / pick_random_theme
Created June 20, 2019 11:46
This script helps with testing pelican-themes.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pick_random_theme - Thursday, June 20, 2019
""" This script will choose a random theme from pelican-themes and symlink it
in the project folder. Previously chosen themes are stored in TESTED_THEMES_FILENAME.
To loop through the themes again, delete TESTED_THEMES_FILENAME from disk or change
the filename.
Usage: pick_random_theme
@palevell
palevell / patch.diff
Created November 18, 2019 14:12
this is a patch to fix 'Cannot write' errors related to long tweets
diff --git a/youtube_dl/extractor/twitter.py b/youtube_dl/extractor/twitter.py
index 5f8d90fb4..3cf8e408b 100644
--- a/youtube_dl/extractor/twitter.py
+++ b/youtube_dl/extractor/twitter.py
@@ -392,6 +392,10 @@ class TwitterIE(TwitterBaseIE):
title = description = status['full_text'].replace('\n', ' ')
# strip 'https -_t.co_BJYgOjSeGA' junk from filenames
title = re.sub(r'\s+(https?://[^ ]+)', '', title)
+ # 2019-Nov-18 PAL - BEGIN Truncate long tweets to prevent 'Cannot write' errors
+ if len(title) > 200:
@palevell
palevell / crypto03.py
Created December 17, 2019 11:00
This is the best example of Fernet encryption that I have found.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# crypto03.py - Monday, December 16, 2019
# Ref: https://www.thepythoncode.com/article/encrypt-decrypt-files-symmetric-python
""" This is the best example of Fernet encryption that I have found """
__version__ = '1.0.0'
from datetime import datetime
from shutil import copy2
@palevell
palevell / utils.py
Created December 28, 2019 21:06
Plugging Tweepy into the Django-Allauth package was easier than I thought.
# utils.py - Saturday, December 28, 2019
# -*- coding: utf-8 -*-
""" I have been experimenting to see which web framework would make the better
wrapper for Tweepy. I decided on Django, with the Allauth package.
Afer going through the Django-Allauth Tutorial at
https://wsvincent.com/django-allauth-tutorial/ and playing with the DjangoTweepy repository at
https://github.com/martinjc/DjangoTweepy/blob/master/src/twitter_auth/utils.py,
this is what I contrived.
@palevell
palevell / update_settings
Created December 28, 2019 21:31
This is a utily script to update the settings.py file in Django projects, based on the contents of the .env file. It also adds code for dotenv support.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# update_settings - Monday, December 23, 2019
__version__ = '1.1.10'
import os, re
from glob import glob
from os.path import basename, dirname, exists, getmtime, join