Skip to content

Instantly share code, notes, and snippets.

View Mufaddal1125's full-sized avatar
๐Ÿ“š
Learning

Mufaddal Patanwala Mufaddal1125

๐Ÿ“š
Learning
  • Cleverflow
  • Mumbai, India.
View GitHub Profile
@Mufaddal1125
Mufaddal1125 / gist:9a1b0a4372ce908b5889049a41faa16d
Created July 15, 2025 15:02
Django admin custom filter that limits the choices for related fields to only those related to the current queryset, based on active filters and search terms. This ensures that dropdowns only show relevant options, improving usability for large datasets.
class LimitedChoiceRelatedListFilter(admin.RelatedOnlyFieldListFilter):
def field_choices(self, field, request, model_admin):
qs = model_admin.get_queryset(request)
for param, value in request.GET.items():
# ignore reserved keywords
if param in ["o", "e", "q"]:
continue
if value:
qs = qs.filter(**{param: value})
# also filter for search
@Mufaddal1125
Mufaddal1125 / docker-compose.yml
Last active March 16, 2024 14:59
Django server with postgres and redis
version: "3.8"
services:
web:
command:
["sh", "-c", "python manage.py migrate && python manage.py runserver"]
volumes:
- .:/app
working_dir: /app
ports:
setState(() {
// change the size of the container
height = 300;
width = 300;
});
AnimatedContainer(
color: Colors.blue,
// give the animation duration
duration: const Duration(milliseconds: 300),
// assign the height and width to the container
height: height,
width: width,
child: Center(
child: Text(
'Animate Me',
@Mufaddal1125
Mufaddal1125 / animated container height.dart
Created July 27, 2022 17:09
animated container height
// set the initial size of the container
double height = 200;
double width = 200;
void _scrollToWidget() async {
// find the index of fruit to scroll to in fruits
// let's scroll to Mandarina
final index = fruits.indexOf('Mandarina');
// get global key of Mandarina
final key = _fruitKeys[index];
// find the render box of Mandarina
var box = key.currentContext?.findRenderObject();
_scrollController.position.ensureVisible(
@Mufaddal1125
Mufaddal1125 / scroll_to_widget_function.dart
Last active July 27, 2022 05:23
scroll to widget method
void _scrollToWidget() async {
// find the index of fruit to scroll to in fruits
// let's scroll to Mandarina
final index = fruits.indexOf('Mandarina');
// get global key of Mandarina
final key = _fruitKeys[index];
// find the render box of Mandarina
var box = key.currentContext?.findRenderObject();
// if box is not in the view port, scroll to it
@Mufaddal1125
Mufaddal1125 / create_scrollcontroller.dart
Last active July 26, 2022 18:41
create scrollcontroller
final _scrollController = ScrollController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ListView.builder(
// assign scroll controller to list view
controller: _scrollController,
itemBuilder: (context, index) {
// list of fruits
var fruits = [
'Apple',
'Banana',
'Cherry',
'Grape',
'Kiwi',
'Mango',
'Orange',
'Pear',
@Mufaddal1125
Mufaddal1125 / AutoSaveSnip.ps1
Created March 11, 2022 06:13
PowerShell Script to automatically save screen snips on windows
# Add this script to Task Scheduler
# and schedule it to run at logon
# in the action start a powershell program and give the arguments
# -Command "Get-Content -Path '<Path To Script>' -Raw | Invoke-Expression"
$watcher = New-Object System.IO.FileSystemWatcher;
$watcher.Path = "$HOME\AppData\Local\Packages\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\TempState\ScreenClip";