Skip to main content

Create a Floyd’s Triangle

0 likes • May 31, 2023 • 0 views
Python
Loading...

More Python Posts

screencap.py

0 likes • Jan 23, 2021 • 0 views
Python
"""
Take screenshots at x interval - make a movie of doings on a computer.
"""
import time
from datetime import datetime
import ffmpeg
import pyautogui
while True:
epoch_time = int(time.time())
today = datetime.now().strftime("%Y_%m_%d")
filename = str(epoch_time) + ".png"
print("taking screenshot: {0}".format(filename))
myScreenshot = pyautogui.screenshot()
myScreenshot.save(today + "/" + filename)
time.sleep(5)
#
# and then tie it together with: https://github.com/kkroening/ffmpeg-python/blob/master/examples/README.md#assemble-video-from-sequence-of-frames
#
"""
import ffmpeg
(
ffmpeg
.input('./2021_01_22/*.png', pattern_type='glob', framerate=25)
.filter('deflicker', mode='pm', size=10)
.filter('scale', size='hd1080', force_original_aspect_ratio='increase')
.output('movie.mp4', crf=20, preset='slower', movflags='faststart', pix_fmt='yuv420p')
.run()
)
"""

hex to rgb

0 likes • Nov 19, 2022 • 2 views
Python
def hex_to_rgb(hex):
return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
hex_to_rgb('FFA501') # (255, 165, 1)

Shuffle Deck of Cards

0 likes • May 31, 2023 • 1 view
Python
import random
# Define the ranks, suits, and create a deck
ranks = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades']
deck = [(rank, suit) for rank in ranks for suit in suits]
# Shuffle the deck
random.shuffle(deck)
# Display the shuffled deck
for card in deck:
print(card[0], "of", card[1])

find parity outliers

0 likes • Nov 19, 2022 • 0 views
Python
from collections import Counter
def find_parity_outliers(nums):
return [
x for x in nums
if x % 2 != Counter([n % 2 for n in nums]).most_common()[0][0]
]
find_parity_outliers([1, 2, 3, 4, 6]) # [1, 3]

Untitled

0 likes • Apr 21, 2023 • 0 views
Python
print("hellur")

Selection sort

0 likes • Nov 19, 2022 • 0 views
Python
# Python program for implementation of Selection
# Sort
import sys
A = [64, 25, 12, 22, 11]
# Traverse through all array elements
for i in range(len(A)):
# Find the minimum element in remaining
# unsorted array
min_idx = i
for j in range(i+1, len(A)):
if A[min_idx] > A[j]:
min_idx = j
# Swap the found minimum element with
# the first element
A[i], A[min_idx] = A[min_idx], A[i]
# Driver code to test above
print ("Sorted array")
for i in range(len(A)):
print("%d" %A[i]),