Skip to content

Instantly share code, notes, and snippets.

View mingsai's full-sized avatar
🎯
Focusing

Tommie N. Carter, Jr. mingsai

🎯
Focusing
View GitHub Profile
// Subscribe to any incoming purchases at app initialization. These can
// propagate from either storefront so it's important to listen as soon as
// possible to avoid losing events.
class _MyAppState extends State<MyApp> {
StreamSubscription<List<PurchaseDetails>> _subscription;
@override
void initState() {
final Stream purchaseUpdates =
InAppPurchaseConnection.instance.purchaseUpdatedStream;
In App Purchase
A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store (on iOS) and Google Play (on Android).
Features
Add this to your Flutter app to:
Show in app products that are available for sale from the underlying shop. Includes consumables, permanent upgrades, and subscriptions.
Load in app products currently owned by the user according to the underlying shop.
Send your user to the underlying store to purchase your products.
Getting Started
@mingsai
mingsai / autogrowth_textfield.dart
Last active May 27, 2020 21:48
Flutter Autogrowth TextField
class _MyScreenState extends State<MyScreen> {
double _inputHeight = 50;
final TextEditingController _textEditingController = TextEditingController();
@override
void initState() {
super.initState();
_textEditingController.addListener(_checkInputHeight);
}
@mingsai
mingsai / form_validation_example.dart
Created May 25, 2020 10:55
Flutter Form Validation Example
import 'package:flutter/material.dart';
import 'package:validate/validate.dart';
void main() => runApp(new MaterialApp(
title: 'Forms in Flutter',
home: new LoginPage(),
));
class LoginPage extends StatefulWidget {
@override
@mingsai
mingsai / apache_htaccess_guide.txt
Created May 20, 2020 12:00
Apache .htaccess rules and samples
Modules | Directives | FAQ | Glossary | Sitemap
Apache HTTP Server Version 2.4
<-
Apache > HTTP Server > Documentation > Version 2.4 > Rewrite
Redirecting and Remapping with mod_rewrite
Available Languages: en | fr
@mingsai
mingsai / hide_sub_directory.txt
Created May 20, 2020 11:58
Rewrite rules to hide folders (sub sites)
To hide the microsite directory in url, you can use the following rules:
<rewrite>
<rules>
<rule name="HideMicroSite" stopProcessing="true">
<match url="^microsite/(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^site\.com$" />
</conditions>
<action type="Redirect" url="{R:1}" />
@mingsai
mingsai / flutter_mysql_notes.txt
Last active February 23, 2022 07:13
Flutter (app) to MySQL(Hosted on Google Cloud) via use of the PHP-CRUD-API Diagnoses and Resolution
Note: This example contains Chinese text and a payload of nested JSON. The payload had to be encoded as a string before being passed on to the API. I found that using the flutter http package one has to use a workaround to decode the characters properly (dart-lang/http#243). The alternative is to use the dio package which encodes everything as utf-8 properly. When decoding the get request, one has to remember to also decode the nested json separately.
Fix for others having this issue:
Flutter has a new network profiler in the Dart tools. Using this I was able to see that an error returned that Field payload does not have a default value.
Solution:
Add a default NULL value to the payload field and with that inserts are now working.
My payload is a json field so I had to jsonEncode(payload) before adding it to the post (in my toJson method)
Also found that I could simply wrap the entire jsonEncode(post) with single quotes
@mingsai
mingsai / network_service.dart
Created May 16, 2020 12:08
Network Service - with cookies to be used for authentication
class NetworkService {
final JsonDecoder _decoder = new JsonDecoder();
final JsonEncoder _encoder = new JsonEncoder();
Map<String, String> headers = {"content-type": "text/json"};
Map<String, String> cookies = {};
void _updateCookie(http.Response response) {
String allSetCookie = response.headers['set-cookie'];
@mingsai
mingsai / uri_encode_library.dart
Created May 15, 2020 19:43
URI encode/decode library for Dart
/*
* Encode/Decode functions for Dart
*
* Copyright 2011 Google Inc.
* Neil Fraser (fraser@google.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@mingsai
mingsai / powershell_split_csv_by_column_value.ps
Created May 13, 2020 17:29
Power shell - Split csv file by column value
Import-Csv $fullpath -Delimiter "`t" -Header Year, ParentID |
Select-Object -Skip 1 |
ForEach-Object {
$parent = $_.ParentID
$_.Year -replace '.*?"(.*?)".*', '$1' | Out-File "$path\$parent.txt" -Append
}