Skip to content

Instantly share code, notes, and snippets.

View vijinho's full-sized avatar

Vijay vijinho

  • England
View GitHub Profile
@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:
@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_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 / 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 / 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
<?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 / drop_tables.sh
Created August 21, 2015 18:14
drop empty tables
#!/bin/sh
# path settings
MYSQL=`which mysql`
# mysql settings
DB="MYDB"
HOST="127.0.0.1"
USER="root"
PASS="root"
@vijinho
vijinho / get_memory_used.php
Last active January 6, 2025 13:00
get memory used in php
<?php
/**
* Get memory usage in megabytes.
*
* @return string Memory usage in the format "used/peak" where both values are in MB.
*/
function get_memory_used(): string {
$memoryUsage = memory_get_usage() / 1024 / 1024;
$peakMemoryUsage = memory_get_peak_usage() / 1024 / 1024;
@vijinho
vijinho / dump_mysql_db_schema.sh
Created August 21, 2015 18:17
dump mysql database schema
#!/bin/sh
MYSQLDUMP=`which mysqldump`
DB="mysql"
HOST="127.0.0.1"
USER="root"
PASS="root"
# backup file settings
@vijinho
vijinho / dump_mysql_db.sh
Created August 21, 2015 18:20
dump a database with selective rows and tables
#!/bin/sh
MYSQLDUMP=`which mysqldump`
# mysql settings
DB="mysql"
HOST="127.0.0.1"
USER="root"
PASS="root"