Skip to content

Instantly share code, notes, and snippets.

@dolphinsue319
dolphinsue319 / LeetCode161.swift
Last active November 21, 2021 06:48
LeetCode 161. One Edit Distance
class Solution {
func isOneEditDistance(_ s: String, _ t: String) -> Bool {
if (s.count == t.count) {
return countOfReplaced(s, t) == 1
}
if (s.count == t.count - 1) {
return isRemoved(s, t)
}
if (t.count == s.count - 1) {
@dolphinsue319
dolphinsue319 / LogisticRegressionThroughSklearn.py
Created April 9, 2017 04:54
用 scikit-learn 實作 logistic regression
# coding: utf-8
# In[ ]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
get_ipython().magic('matplotlib inline')
@dolphinsue319
dolphinsue319 / SimplestKeras.py
Last active November 22, 2019 10:57
這是一個最簡短、最基本的 Keras 使用範例。
# 這段程式碼來自莫煩 Python: https://morvanzhou.github.io/tutorials/machine-learning/keras/2-1-regressor/
from keras.models import Sequential
from keras.layers import Dense
import matplotlib.pyplot as plt
import numpy as np
# 建立 X, Y 兩組資料用來練習 keras 的使用
X = np.linspace(-1, 1, 200)
np.random.shuffle(X)
Y = 0.5 * X + 2 + np.random.normal(0, 0.05, (200, ))
# coding=utf-8
from peewee import *
import datetime
class DateHandler:
def __init__(self):
pass
THIS_YEAR = datetime.datetime.now().year
@dolphinsue319
dolphinsue319 / fetch_stocks_price.py
Created March 3, 2017 09:25
Fetch Taiwan OTC stocks price.
# coding=utf-8
import StringIO
import csv
import requests
from bs4 import BeautifulSoup
import time
import random
from Models import *
@dolphinsue319
dolphinsue319 / check_facebook_request.py
Last active February 1, 2017 08:13
Check Facebook's webhook request
@app.route('/', methods=['GET'])
def verify():
# when the endpoint is registered as a webhook, it must echo back
# the 'hub.challenge' value it receives in the query arguments
if request.args.get("hub.mode") == "subscribe" and request.args.get("hub.challenge"):
if not request.args.get("hub.verify_token") == os.environ["VERIFY_TOKEN"]:
return "Verification token mismatch", 403
return request.args["hub.challenge"], 200
@dolphinsue319
dolphinsue319 / send_message_to_Facebook.py
Last active February 1, 2017 08:13
send message to Facebook
def send_message(recipient_id, message_text):
params = {
"access_token": os.environ["PAGE_ACCESS_TOKEN"]
}
headers = {
"Content-Type": "application/json"
}
data = json.dumps({
"recipient": {
"id": recipient_id
@dolphinsue319
dolphinsue319 / mock_message_location.json
Last active February 1, 2017 05:38
The json string from Facebook's post request.
{
"entry": [
{
"id": "entry_id",
"time": 1485670019761,
"messaging": [
{
"sender": {
"id": "USER_ID"
},
@dolphinsue319
dolphinsue319 / tailTogether.sh
Created October 15, 2016 13:24
Observe watch app and iPhone app's console log at the same time.
#!/bin/bash
myArray=($(xcrun simctl list pairs | grep Booted | cut -d "(" -f2 | cut -d ")" -f1))
tail -f ~/Library/Logs/CoreSimulator/${myArray[0]}/system.log -f ~/Library/Logs/CoreSimulator/${myArray[1]}/system.log
@dolphinsue319
dolphinsue319 / SourceEditorCommandSample.swift
Created September 10, 2016 12:24
Sample of SourceEditorCommand.swift
import Foundation
import XcodeKit
class SourceEditorCommand: NSObject, XCSourceEditorCommand {
func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping (Error?) -> Void ) -> Void {
// Implement your command here, invoking the completion handler when done. Pass it nil on success, and an NSError on failure.
print("command identifier: \(invocation.commandIdentifier)")
print("content UTI: \(invocation.buffer.contentUTI)")
print("tab width: \(invocation.buffer.tabWidth)")