This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
let a = #imageLiteral(resourceName: "hot.png") | |
extension NSImage { | |
var toCGImage: CGImage { | |
var imageRect = NSRect(x: 0, y: 0, width: size.width, height: size.height) | |
guard let image = cgImage(forProposedRect: &imageRect, context: nil, hints: nil) else { | |
abort() | |
} | |
return image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# https://stackoverflow.com/questions/32892932/create-the-oriented-bounding-box-obb-with-python-and-numpy | |
def oobb(pts): | |
''' | |
given: | |
pts, 2d or 3d | |
return: | |
corners, center of the oobb | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// plain write to image | |
@discardableResult func writeCGImage(_ image: CGImage, to destinationURL: URL) -> Bool { | |
guard let destination = CGImageDestinationCreateWithURL(destinationURL as CFURL, kUTTypePNG, 1, nil) else { return false } | |
CGImageDestinationAddImage(destination, image, nil) | |
return CGImageDestinationFinalize(destination) | |
} | |
// There's a panel, save image png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
protocol DragContainerDelegate { | |
func draggingEntered() | |
func draggingExit() | |
func draggingFileAccept(_ files: [URL]) | |
} | |
// https://stackoverflow.com/questions/29233247/implementing-a-drag-and-drop-zone-in-swift | |
class DragContainer: NSView { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/38754668/plane-fitting-in-a-3d-point-cloud | |
def PCA(data, correlation = False, sort = True): | |
""" Applies Principal Component Analysis to the data | |
Parameters | |
---------- | |
data: array | |
The array containing the data. The array must have NxM dimensions, where each | |
of the N rows represents a different individual record and each of the M columns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/15753701/how-can-i-pass-a-list-as-a-command-line-argument-with-argparse | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-i', '--input',type = str, default = "sample.json") | |
parser.add_argument( "-l","--list", nargs="*", type=int, default=[0,1,2]) | |
args = parser.parse_args() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_data_from_file( filename ): | |
with open(filename, 'r') as json_file: | |
data = json.load(json_file) | |
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/48609781/distance-between-one-point-and-rest-of-the-points-in-an-array/48610147 | |
from scipy.spatial import distance | |
X = [(35.0456, -85.2672)] | |
coords = [(35.1174, -89.9711), | |
(35.9728, -83.9422), | |
(36.1667, -86.7833)] | |
distance.cdist(X, coords, 'euclidean') | |
array([[ 4.70444794, 1.6171966 , 1.88558331]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
files = os.listdir() | |
# files is a string list | |
for filename in files: | |
print(filename) | |
# https://askubuntu.com/questions/443830/delete-all-files-whose-filenames-contain-a-particular-string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open('filename') as f: | |
lines = f.readlines() | |
with open('write','w') as f: | |
f.write('Hello\n') |
NewerOlder