Skip to content

Instantly share code, notes, and snippets.

Avatar

e96031413

View GitHub Profile
@e96031413
e96031413 / pytorch_numpy.py
Created Sep 11, 2020
some pytorch and numpy usage
View pytorch_numpy.py
# torch.unsqueeze(1)可以新增shape
example:
x_val = torch.Size([10000, 28, 28])
x_val = x_val.unsqueeze(1)
# [out] torch.Size([10000, 1, 28, 28])
# the ToTensor method to convert images into PyTorch tensors.
# passed the transformer function to the dataset class. This way, data
# transformation will happen on-the-fly. This is a useful technique for large datasets that
@e96031413
e96031413 / 指定使用GPU.py
Created Aug 27, 2020
兩個指定使用哪一顆GPU的方法
View 指定使用GPU.py
# CLI
! CUDA_VISIBLE_DEVICES=1 python train.py
# Inside train.py
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
# 執行時,會出現GPU的編號,此編號並非實際GPU序號,而是把第1張GPU當成第0張使用
@e96031413
e96031413 / perm.py
Created Jul 31, 2020
使用itertools.permutations(x)列出所有element的可能組合
View perm.py
#使用itertools.permutations(x)列出所有element的可能組合
import itertools
x = ['1','2','3']
perm = itertools.permutations(x)
for i in perm:
print(i)
@e96031413
e96031413 / google-drive-download.sh
Created Jul 27, 2020
Download Google Drive Files From Linux Server
View google-drive-download.sh
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=FILEID" -O FILENAME && rm -rf /tmp/cookies.txt
@e96031413
e96031413 / python_class_usage.py
Created Jul 11, 2020
Python物件導向觀念練習 - 以ATM存提款為例
View python_class_usage.py
class Bank(object):
def __init__(self):
self.balance = 1000 #預設存款1000
def deposit_money(self, amount): # CREATE
return self.balance + amount
def get_balance(self): # READ
return self.balance
@e96031413
e96031413 / 防止Google Colab自动断开代码.js
Created Jul 10, 2020
防止Google Colab自动断开代码
View 防止Google Colab自动断开代码.js
// 每60分钟自动运行代码刷新,解除90分钟断开限制.
// 使用方法:colab页面按下 F12或者 Ctrl+Shift+I (mac按 Option+Command+I) 在console(控制台) 输入以下代码并回车.
// 复制以下代码粘贴在浏览器console!!不要关闭浏览器以免失效
function ConnectButton(){
console.log("Connect pushed");
document.querySelector("#connect").click()
}
setInterval(ConnectButton,60000);
@e96031413
e96031413 / custom-css-inside-block-with-Pug.html
Last active Jun 12, 2020
使用Pug縮排語法撰寫HTML和CSS
View custom-css-inside-block-with-Pug.html
<!--
self closing elements:如meta標籤、img標籤,只要單行就可以結尾,不用縮排
一般的elements:<div>、<style>需要</div>、</style>的,則需要縮排
.google-review-img = <div class="google-review-img"></div>
可使用 https://pughtml.com/ 進行Pug to html語法轉換
-->
@e96031413
e96031413 / custom-css-inside-block.html
Last active Jun 12, 2020
在html中針對一個小block自定義CSS效果
View custom-css-inside-block.html
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.google-review-img{
background-color: #2693B0;
text-align: center;
display: block;
max-width:100%;
width:100%;
}
@e96031413
e96031413 / secureStorage.dart
Created Jun 10, 2020
Function to deal with google auth credentials
View secureStorage.dart
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:googleapis_auth/auth_io.dart';
class SecureStorage {
final storage = FlutterSecureStorage();
//Save Credentials
Future saveCredentials(AccessToken token, String refreshToken) async {
print(token.expiry.toIso8601String());
await storage.write(key: "type", value: token.type);
@e96031413
e96031413 / googleDrive.dart
Created Jun 10, 2020
Sign in Google Auth with WebView and User-agent on Flutter
View googleDrive.dart
import 'dart:async';
import 'dart:io';
import 'package:MainCamera/GoogleDrive/secureStorage.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:googleapis/drive/v3.dart' as ga;
import 'package:googleapis_auth/auth_io.dart';
import 'package:http/http.dart' as http;
import 'package:path/path.dart' as p;
You can’t perform that action at this time.