Skip to content

Instantly share code, notes, and snippets.

View automactic's full-sized avatar

ChrisLi automactic

View GitHub Profile
@automactic
automactic / send_data.py
Created July 28, 2017 18:36
python KSensor WebAPI request sample code
from datetime import datetime
import json
import urllib.request
def send_data(url: str, sid, pknnmb, timestamp: datetime, baseline, stddev, measures):
payload = {
'sid': str(sid),
'pknmb': str(pknnmb),
'timestamp': timestamp.strftime('%Y-%m-%d %H:%M:%S'),
import subprocess
import os
def change_install_name(lib_install_path: str):
def get_name_map(dir_path: str):
files = {}
for file in os.listdir(dir):
if file.endswith('.dylib') and not os.path.islink(dir_path+'/'+file):
files[file.split('.')[0]] = file
@automactic
automactic / fat_lib.py
Last active August 16, 2017 21:56
fat_lib.py
import subprocess
import distutils.dir_util
import os
def generate_fat_libs(root: str, archs: [str], output: str):
def get_lib_names(dir: str) -> [str]:
libs = []
for file in os.listdir(dir):
if file.endswith('.dylib') and not os.path.islink(dir + '/' + file):
func configSearchMenu() {
let clear = NSMenuItem(title: "Clear", action: nil, keyEquivalent: "")
clear.tag = Int(NSSearchFieldClearRecentsMenuItemTag)
searchMenu.insertItem(clear, at: 0)
searchMenu.insertItem(NSMenuItem.separator(), at: 0)
let recents = NSMenuItem(title: "", action: nil, keyEquivalent: "")
recents.tag = Int(NSSearchFieldRecentsMenuItemTag)
searchMenu.insertItem(recents, at: 0)
@automactic
automactic / example.js
Created October 18, 2017 14:21
js in zim
function TableOfContents () {
this.getSections = function() {
/*
- return an array of section objects
- in case there there is no table of content, return an empty array
*/
}
this.scrollToSection = function(index: number) {
/*
@automactic
automactic / ViewController.swift
Created January 10, 2018 02:14
Broken iOS 11 NavigationBar
import UIKit
class ViewController: UIViewController {
let button = UIBarButtonItem(barButtonSystemItem: .add, target: nil, action: nil)
override func viewDidLoad() {
super.viewDidLoad()
let searchBar = UISearchBar()
searchBar.searchBarStyle = .minimal
navigationItem.titleView = searchBar
}
@automactic
automactic / Levenshtein.swift
Created January 17, 2018 22:13
Levenshtein distance in swift 4
class Levenshtein {
private(set) var cache = [Set<String.SubSequence>: Int]()
func calculateDistance(a: String.SubSequence, b: String.SubSequence) -> Int {
let key = Set([a, b])
if let distance = cache[key] {
return distance
} else {
let distance: Int = {
if a.count == 0 || b.count == 0 {
@automactic
automactic / gist:842669d1ab1be9953f8d252824c8c5bc
Created January 24, 2018 04:18
Interactive Controller Experiments
//
// InteractiveController.swift
// iOS
//
// Created by Chris Li on 1/22/18.
// Copyright © 2018 Chris Li. All rights reserved.
//
import UIKit
@automactic
automactic / gist:2f6db1e1eac0dcff6a0c4f552ba5de98
Created January 24, 2018 16:28
Interactiva Controller with Custom Presentation
// https://www.raywenderlich.com/139277/uipresentationcontroller-tutorial-getting-started
// PanelViewController.swift
// iOS
//
// Created by Chris Li on 1/23/18.
// Copyright © 2018 Chris Li. All rights reserved.
//
import UIKit
(venv) Chriss-MacBook-Pro:worker chrisli$ python worker
=========================================================
Welcome to Zimfarm worker:
=========================================================
Let's check some settings:
* current values are in '[]'
* accept current values by pressing enter
Username [admin]: