Skip to content

Instantly share code, notes, and snippets.

View vijinho's full-sized avatar

Vijay vijinho

  • England
View GitHub Profile
<?php
/**
* Validate and adjust year and month parameters, calculate date range for a complete whole month,
* and add MySQL date and Unix timestamp values to the params.
*
* Default to current year and month if there's a problem.
*
* @param array $params - requires 'year' and 'month' as int or will default to current values
* @return array
*/
@vijinho
vijinho / find-extensions.sh
Last active January 6, 2025 10:21
List the file extensions found for a given directory tree, default current directory
#!/bin/bash
# Function to display usage information
usage() {
echo "Usage: $0 [-d | --directory] <directory>"
echo " -d, --directory Specify the directory to search (default: current directory)"
exit 1
}
# Default directory is the current directory
@vijinho
vijinho / kivy_image_rescale.py
Last active January 6, 2025 11:50
Python Kivy: Rescale an image to fit a given viewport size without losing aspect ratio
class MyImage(Image):
def __init__(self, **kwargs):
super(MyImage, self).__init__()
def texture_width(self):
return self.texture.size[0]
def texture_height(self):
return self.texture.size[1]
@vijinho
vijinho / kivy_image_orientation.py
Last active January 6, 2025 11:50
Determine image orientation from width and height
def orientation(self, width, height):
"""
Determine an image orientation based on width and height
:param w: width
:param h: height
:return: boolean (landscape, portrait, square)
"""
square = False
landscape = False
portrait = False
@vijinho
vijinho / setfonts.py
Last active January 6, 2025 10:47
Code Snippet: Python Kivy - Set fonts from files
from kivy.core.text import LabelBase
KIVY_FONTS = [
{
"name": "Ubuntu",
"fn_regular": "assets/fonts/ubuntu/Ubuntu-L.ttf",
"fn_bold": "assets/fonts/ubuntu/Ubuntu-M.ttf",
"fn_italic": "assets/fonts/ubuntu/Ubuntu-LI.ttf",
"fn_bolditalic": "assets/fonts/ubuntu/Ubuntu-MI.ttf"
}
]
@vijinho
vijinho / kivy_is_desktop.py
Last active January 6, 2025 11:50
SNIPPET: Python Kivy - Detect if running on a desktop platform
from kivy.utils import platform
def is_desktop():
"""
Detect if we are running on the desktop or not
:return: boolean True if running on a desktop platform or String platform
"""
if platform in ('linux', 'win', 'macosx'):
return True
else: