Skip to content

Instantly share code, notes, and snippets.

View tranductam2802's full-sized avatar
🔥
Fulltime Mobile Developer! Part-time Poker dealer

Trần Đức Tâm tranductam2802

🔥
Fulltime Mobile Developer! Part-time Poker dealer
View GitHub Profile
@tranductam2802
tranductam2802 / master_boot_record_viewer.py
Created October 8, 2019 05:38
Master Boot Record format memo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import distorm3
import hashlib
import struct
import sys
PARTITION_TYPES = {
@tranductam2802
tranductam2802 / server.py
Created October 10, 2019 05:40
Python proxy server for forwarding request.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Usage:
- Windows OS:
$ set FORWARD_HOST=http://example.com[:port]
$ python server.py
- Unix based OS (Ubuntu, MacOS .etc):
$ export FORWARD_HOST=http://example.com[:port]
$ python server.py"""
@tranductam2802
tranductam2802 / catch-a-threads-exception-in-the-caller-thread-in-python.md
Last active October 16, 2019 03:01
Best question about Python on Stackoverflow.

Catch a thread's exception in the caller thread in Python

The problem is that thread_obj.start() returns immediately. The child thread that you spawned executes in its own context, with its own stack. Any exception that occurs there is in the context of the child thread, and it is in its own stack. One way I can think of right now to communicate this information to the parent thread is by using some sort of message passing, so you might look into that.

Try this on for size:

import sys
import threading
import Queue

# w = (A^T)^+b = ((X^T)X)^+(X^T)y
import numpy as np
import matplotlib.pyplot as plt
x = [0, 1, 2]
X = np.array([x]).T
y = [0, 1, 2]
Y = np.array([y]).T
@tranductam2802
tranductam2802 / main.dart
Last active October 28, 2020 03:24
Demo the basic action with dialog. (cancelOnTouchOutside, dismiss listener, call GUI function after dismiss)
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Tutorial by Tran Duc Tam',
home: ProcessPage(),
@tranductam2802
tranductam2802 / main.dart
Last active August 5, 2021 18:22
A TabBar supported for bubble view style and wheel scroll
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() async =>
runApp(MaterialApp(debugShowCheckedModeBanner: false, home: DemoScreen()));
class DemoScreen extends StatefulWidget {
@override
_DemoScreenState createState() => _DemoScreenState();
}
@tranductam2802
tranductam2802 / git.command
Last active December 19, 2019 08:33
Git command memo on gist
# Check the commit rank and list of commiter
$ git config --global alias.rank "shortlog -sn --no-merges"
# Shortern amend
$ git config --global alias.amend "commit --amend --no-edit"
# First 10 commit from all repository
$ git config --global alias.head "log -n 10 --all --graph --oneline --pretty=format:'%Cred%h%Cblue%d%Creset %s %C(bold yellow)<%an> %Cgreen[%cr]%Creset' --abbrev-commit"
# First 10 commit from all repository with detail information
@tranductam2802
tranductam2802 / dart_async_demo.dart
Last active January 8, 2020 03:13
Demo for understanding dart async.
import 'dart:async';
main() {
Future(() => print('Line 1'));
scheduleMicrotask(() => print('Line 2'));
print('Line 3');
print('Line 4');
Future(() {
Future(() => print('Line 5'));
scheduleMicrotask(() => print('Line 6'));
@tranductam2802
tranductam2802 / main.dart
Last active October 28, 2020 03:15
Demo auto hide header of the scroll view
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() {
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
@tranductam2802
tranductam2802 / main.dart
Last active October 28, 2020 03:11
Demo input parameter for enum extension
enum SelectedColor {
primaryColor,
secondaryColor,
}
extension SelectedColorExtension on SelectedColor {
String get name => describeEnum(this);
String displayTitle(index) {
print(index);