Skip to content

Instantly share code, notes, and snippets.

View craiglabenz's full-sized avatar

Craig Labenz craiglabenz

View GitHub Profile
@craiglabenz
craiglabenz / repaint_boundary.dart
Created February 25, 2022 18:05
Demonstrates the use of RepaintBoundary
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
// Setting this is the same as enabling the feature in your IDE.
debugRepaintRainbowEnabled = true;
runApp(const MyApp());
@craiglabenz
craiglabenz / stale_buildcontext.dart
Created February 22, 2022 20:20
Demonstrates how use of the wrong BuildContext can yield unexpected results
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@craiglabenz
craiglabenz / mediaquerydata-demo.dart
Last active August 12, 2024 16:51
Demonstrates Padding vs ViewPadding vs ViewInsets
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
@craiglabenz
craiglabenz / view_insets.dart
Created January 11, 2020 16:53
Flutter fails to report keyboard size via `MediaQuery.of(context).size`
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
[
{
"id": 1,
"name": "Yay"
}
]
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Vessel>
<Updated>2015-01-01</Updated>
</Vessel>
</Root>
@craiglabenz
craiglabenz / xpath-fail.py
Last active November 6, 2015 22:56
The following code (which `webook_api.py` executes) produces an empty list, whereas copying the same values in here (http://www.freeformatter.com/xpath-tester.html#ad-output) produces the expected output
from lxml import etree
from StringIO import StringIO
from django.utils.encoding import smart_str
# Skip down to the bottom of this massive XML blob for more fun!
content = """<?xml version="1.0" encoding="utf-8"?>
<Root xsi:noNamespaceSchemaLocation="Questionnaire88_Template.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ResponseHeader Code="101" Date="2015-11-06T22:09:53.4155282Z">
CREATE TABLE `persons` (
`sid` int(11) NOT NULL,
`is_active_user` tinyint(1) NOT NULL,
`is_premium` tinyint(1) NOT NULL,
`is_staff` tinyint(1) NOT NULL,
`is_superuser` tinyint(1) NOT NULL,
`is_deactivated` tinyint(1) NOT NULL,
`is_merged_out` tinyint(1) NOT NULL,
`password` varchar(128) NOT NULL,
`last_login` datetime DEFAULT NULL,
@classmethod
def my_func(cls, *args):
'''
A model function -- not a full Django View.
'''
with transaction.commit_manually(using='custom_connection'):
obj = OtherModel.objects.get(...)
try:
# do stuff
obj.save()
@craiglabenz
craiglabenz / cache_checker.py
Created June 11, 2013 15:14
Django < 1.6 template chunk key checker
# standard lib
import hashlib
# django
from django.core.cache import cache
from django.utils.encoding import force_bytes
from django.utils.http import urlquote
def make_template_fragment_key(fragment_name, vary_on=[]):