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
@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
}
@mingsai
mingsai / awk_split_csv_with_headers_by_value.sh
Created May 13, 2020 17:20
Awk - Split csv file by value and retain header
#retains header
awk -F, 'NR==1 {h=$0; next} {f=$3".csv"} !($3 in p) {p[$3]; print h > f} {print >> f}' input.csv
#option 2
HDR=$(head -1 input.csv); for fn in $(tail -n+2 input.csv | cut -f3 -d, | sort -u); do echo $HDR > $fn.csv; done
awk -F, '{print >> ($3".csv")}' input.csv
@mingsai
mingsai / split_csv_by_field_values.pl
Created May 13, 2020 17:17
Perl - Split CSV by field value and retain header
open $fh, '<', $ARGV[0];
while ($line = <$fh>) {
print $line;
if ($. == 1) {
$header = $line;
} else {
# $fields[2] is the 3rd column
@fields = split /,/, $line;
# save line into hash %c
$c{"$fields[2].csv"} .= $line;