Skip to content

Instantly share code, notes, and snippets.

View mdecourse's full-sized avatar

KMOLab mdecourse

  • KMOL
  • Taiwan
View GitHub Profile
@mdecourse
mdecourse / 1agrp_2022
Last active June 13, 2022 16:19
Brython examples
# 2a w3 grouping program, 與 2b 處理架構相同
from browser import html
from browser import document
import random
brython_div = document["brython_div"]
# 根據 href 與 content 將 html 元件中的 anchor 插入頁面
def makeLink(href, content):
brython_div <= html.A(content, href=href)
@mdecourse
mdecourse / get_data_from_gist.py
Created January 19, 2022 07:26
Get data from public gist
import json
from urllib.request import urlopen
import os
import math
USER = "mdecourse"
#perpage=30.0
perpage = 100.0
userurl = urlopen('https://api.github.com/users/' + USER)
public_gists = json.load(userurl)
@mdecourse
mdecourse / ajax_brython.py
Last active January 13, 2022 16:04
cp2021 W11
# 從 browser 導入 document
from browser import document
# 使用者可以透過 window 當作介面使用其他 Javascript 功能
from browser import html, window, ajax
# https://www.brython.info/static_doc/en/ajax.html
brython_div = document["brython_div"]
output = html.DIV("output")
output.id = "output"
brython_div <= output
# 從 browser 導入 document 並設為 doc
from browser import document as doc
# 使用者可以透過 window 當作介面使用其他 Javascript 功能
from browser import html, window
# 用於定時執行特定函式
import browser.timer
# 導入數學模組
import math
# 導入亂數模組
from random import random, randint
@mdecourse
mdecourse / kmlo_snakey.py
Last active December 22, 2021 02:56
Brython Snakey for cp2021
# source from https://hawstein.com/2013/04/15/snake-ai/
# snake head is black
# add lightgrey grid
# 從 browser 導入 document 並設為 doc
from browser import document as doc
# 使用者可以透過 window 當作介面使用其他 Javascript 功能
from browser import html, window
# 用於定時執行特定函式
import browser.timer
# 導入數學模組
@mdecourse
mdecourse / bfs.py
Last active November 20, 2021 13:23
Python searching algorithms
# from https://github.com/joeyajames/Python/blob/master/bfs.py
class Vertex:
def __init__(self, n):
self.name = n
self.neighbors = list()
self.distance = 9999
self.color = 'black'
def add_neighbor(self, v):
@mdecourse
mdecourse / guitar_chord1.py
Created November 13, 2021 16:33
Guitar Chords
from browser import document as doc
from browser import html
import math
# 準備繪圖畫布
# 利用 html 建立一個 CANVAS 標註物件, 與變數 canvas 對應
canvas = html.CANVAS(width = 600, height = 400)
# 將 canvas 標註的 id 設為 "cango_gear"
canvas.id = "chord1"
# 將 document 中 id 為 "brython_div" 的標註
# 設為與 brython_div 變數對應
@mdecourse
mdecourse / 1d_fem_ex1.c
Last active November 12, 2021 13:12
Optimization Programs
# include <math.h>
# include <stdlib.h>
# include <stdio.h>
# include <time.h>
//# include "fem1d_bvp_linear.h"
double *fem1d_bvp_linear ( int n, double a ( double x ), double c ( double x ),
double f ( double x ), double x[] );
double h1s_error_linear ( int n, double x[], double u[],
double exact_ux ( double x ) );
@mdecourse
mdecourse / binary_searh.py
Created November 10, 2021 03:20
Python Algorithms
# Iterative Binary Search Function
def binary_search(list1, n):
low = 0
high = len(list1) - 1
mid = 0
while low <= high:
# for get integer result
mid = (high + low) // 2
url = "https://nfulist.herokuapp.com/?semester=1101&courseno=0805&column=True"
data = open(url).readlines()
print(len(data))