Skip to content

Instantly share code, notes, and snippets.

View nick3499's full-sized avatar
🏠
Working from home

nick3499 nick3499

🏠
Working from home
  • USA
View GitHub Profile
@nick3499
nick3499 / dice_roll_probability.js
Last active February 23, 2023 03:18
Dice Roll Probability: Python, JavaScript, Ruby
#! /bin/nodejs
/* Calculate dice roll probability.
n1 = sum of die values
n2 = how many dice */
function rolldiceSumProb(n1, n2) {
lo = ('1').repeat(n2) // ones, e.g. '111'
hi = ('6').repeat(n2) // sixes, e.g. '666'
combos = [] // dice combinations
matches = [] // matching combinations
@nick3499
nick3499 / set_bg_img.py
Created May 24, 2020 05:23
Set background image and display mode in gsettings: subprocess.run(), click
#! /bin/python3
'''`set_bg_img` module contains `set_img()` method which sets image URI and display mode.
$ python3 set_bg_img.py'''
from subprocess import run
from click import command
from click import option
from click import Choice
@command() # command options
@nick3499
nick3499 / get_gist.py
Created April 30, 2020 17:40
Get gist: Python3: io.BytesIO(), pycurl.Curl(): using PycURL to run raw Gist code (Python code) locally
#! /bin/python3
'''Execute raw Gist code (Python code) locally.'''
import pycurl
from io import BytesIO
bytes_io = BytesIO() # init bytesio obj
_curl = pycurl.Curl() # init curl obj
# set raw gist URL
_curl.setopt(_curl.URL, 'https://gist.githubusercontent.com/nick3499/7202dfe86ba7ee0d7e214392fdbdab59/raw/4aa37582274f98ffffd776a69aa08ab6c738beac/convert2nato.py')
@nick3499
nick3499 / roll_dice.py
Last active June 9, 2020 11:09
Python3: Random dice roll results
#! /bin/python3
'''`roll_dice` module contains `roll_dice` method which returns random \
results of two rolled dice.'''
from random import randrange
def roll_dice():
'''`roll_dice()` method returns random results of two dice.'''
die_segments = {
'top' : '┌───────┐',
@nick3499
nick3499 / gm_resize.py
Created April 5, 2020 03:07
Comparison for Image Resize: Python3, os.chdir(), os.listdir(), PIL.Image()
#! /bin/python3
'''`gm_resize` module contains `gm_resize()` method for resizing an image.'''
from os import chdir
from os import listdir
from PIL import Image
def gm_resize():
'''A dimensional comparison is used to determine whether an image should \
be resized based on image width or image height.'''
@nick3499
nick3499 / dsky_scraper.py
Last active April 3, 2020 21:08
Scrape Dark Sky Weather
#! /bin/python3
'''After Dark Sky joined Apple, free API subscriptions closed. Enter the web \
scraper.'''
from lxml import html
from requests import get
_geo = '37.778,-122.4313' # San Francisco
_page = get(f'https://darksky.net/forecast/{_geo}/us12/en')
tree = html.fromstring(_page.content)
@nick3499
nick3499 / random_hostname.py
Last active March 18, 2020 20:11
Set Random Hostname: Python3 random.randrange(), subprocess.run()
#! /bin/python3
'''`random_hostname` module contains the `rand_hostname()` method \
which generates a pseudo-random hostname.'''
from random import randrange
from subprocess import run
def rand_hostname():
'''`rand_hostname()` method generates a pseudo-random hostname.'''
# alphanumeric collection
@nick3499
nick3499 / scifi_wallpaper.py
Last active March 13, 2020 18:10
SciFi Wallpaper: Python3: Set desktop wallpaper image in Bash CLI; center it; tile it: os.listdir(), datetime.date(), subprocess.run(), click
#! /bin/python3
'''`scifi_wallpaper` module contains methods for setting background image.
Along with the display mode. Help: $ python3 scifi_wallpaper.py
opensource.org/licenses/MIT'''
from os import listdir
from datetime import date
from subprocess import run
import click
@nick3499
nick3499 / ascii_radio.txt
Created January 29, 2020 17:47
Python 3: Radio Streams VLC: csv.reader(), subprocess.run()
:::::::.. :::. :::::::-. ::: ...
;;;;``;;;; ;;`;; ;;, `';,;;; .;;;;;;;.
[[[,/[[[' ,[[ '[[, `[[ [[[[[,[[ \[[,
$$$$$$c c$$$cc$$$c $$, $$$$$$$$, $$$
888b "88bo,888 888,888_,o8P'888"888,_ _,88P
MMMM "W" YMM ""` MMMMP"` MMM "YMMMMMP"
@nick3499
nick3499 / pythag_convert.py
Last active April 30, 2020 12:31
Python 3: Convert Letters to Pythagorean Numerology: dict(), input(), list(), upper(), replace(), print()
#! /bin/python3
'''`pythag_convert` module contains `pythag_convert()` method which converts \
text string to Pythagorean number system.'''
from sys import argv
def pythag_convert():
'''pythag_convert() converts text string to Pythagorean numerology system.
$ python3 ~/scripts_path/pythag_convert.py Foo'''
pythag = {