Skip to content

Instantly share code, notes, and snippets.

View nhancv's full-sized avatar
🏠
Working from home

Nhan Cao nhancv

🏠
Working from home
View GitHub Profile
@nhancv
nhancv / su_board.py
Last active July 15, 2018 11:56
Solve sudoku board with python
#Find next empty cell
def findNextCell(board):
for i in xrange (0, 9):
for j in xrange (0, 9):
if(board[i][j] == 0):
return [i, j]
#Check board is full value
def isFull(board):
for i in xrange(0,9):
@nhancv
nhancv / preprocessImg.py
Created July 15, 2018 13:46
preprocessImg
def preprocessImg(image):
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
cv.imshow('gray', gray)
# gray = cv.GaussianBlur(gray, (11, 11), 0)
# outerBox = cv.adaptiveThreshold(gray, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 5, 2)
ret,thresh = cv.threshold(gray,128,255,cv.THRESH_BINARY)
cv.imshow('thresh', thresh)
outerBox = cv.bitwise_not(thresh)
cv.imshow('BitwiseNot', outerBox)
return outerBox
import 'package:flutter/material.dart';
import 'package:scoped_model/scoped_model.dart';
void main() => runApp(MyApp());
class CounterModel extends Model {
int _counter = 0;
int get counter => _counter;
@nhancv
nhancv / main_inherited_widget.dart
Created December 12, 2018 05:56
InheritedWidget
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
@nhancv
nhancv / main_bloc.dart
Last active October 3, 2019 08:03
Simple bloc
import 'dart:async';
import 'package:rxdart/rxdart.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@nhancv
nhancv / global.dart
Created December 12, 2018 15:44
Global env
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
class Env {
Env._({@required this.apiBaseUrl});
final String apiBaseUrl;
factory Env.dev() {
return new Env._(apiBaseUrl: "https://api.github.com");
@nhancv
nhancv / api.dart
Created December 12, 2018 15:48
Flutter api using http
import 'package:http/http.dart' as http;
import 'package:bflutter_poc/global.dart';
class Api {
static final Api _instance = Api._private();
Api._private();
factory Api() => _instance;
final String apiBaseUrl = Global().env.apiBaseUrl;
@nhancv
nhancv / user.dart
Created December 12, 2018 15:53
Flutter user model
import 'package:bflutter_poc/model/user_base.dart';
import 'package:json_annotation/json_annotation.dart';
part 'user.g.dart';
@JsonSerializable()
class User extends UserBase {
User(String login, String avatarUrl, this.name, this.location)
: super(login, avatarUrl);
@nhancv
nhancv / bloc.dart
Last active December 12, 2018 15:59
Bloc base
import 'package:rxdart/rxdart.dart';
class Bloc<I, O> {
var subject = BehaviorSubject<I>();
Function(Observable<I> event) business =
(Observable<I> event) => Observable<O>.empty();
void push(I event) => subject.add(event);
Stream<O> stream() => business(subject);
@nhancv
nhancv / home_bloc.dart
Last active October 3, 2019 08:02
Flutter home screen
import 'dart:convert';
import 'package:bflutter/bflutter.dart';
import 'package:bflutter_poc/api.dart';
import 'package:rxdart/rxdart.dart';
import 'package:bflutter_poc/model/user.dart';
class HomeBloc {
var getUserInfo = Bloc<String, User>();
HomeBloc() {