Skip to content

Instantly share code, notes, and snippets.

@zhangao0086
zhangao0086 / _sum.py
Last active July 1, 2020 08:58
完全平方数的和
#!/usr/bin/python3
# -*-coding:utf-8-*-
__author__ = "Bannings"
def _sum(n: int) -> int:
dp = [[[]]] + [[] for _ in range(n)]
max_num = int(n**0.5)
for i in range(1, max_num + 1):
num = i * i
Log file created at: 2019/01/03 11:20:25
Running on machine: Aos-MacBook-Pro.local
Log line format: [IWEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg
E0103 11:20:25.944139 225560000 deployment_tasks.cc:62] Error reading file information: boost::filesystem::canonical: No such file or directory: "/Users/zhangao/Library/Rime/stroke.reverse.bin"
E0103 11:20:25.947233 72896512 deployment_tasks.cc:488] boost::filesystem::canonical: No such file or directory: "/Users/zhangao/Library/Rime/stroke.reverse.bin"
E0103 11:20:25.947309 72896512 deployment_tasks.cc:488] boost::filesystem::canonical: No such file or directory: "/Users/zhangao/Library/Rime/luna_pinyin_simp.prism.bin"
E0103 11:20:25.947396 72896512 deployment_tasks.cc:488] boost::filesystem::canonical: No such file or directory: "/Users/zhangao/Library/Rime/luna_pinyin_tw.prism.bin"
E0103 11:20:25.947487 72896512 deployment_tasks.cc:488] boost::filesystem::canonical: No such file or directory: "/Users/zhangao/Library/Rime/stroke.table.bin"
E0103 11:20:25.9475
From: ZhangAo <zhangao@shaozi.com>
Content-Type: multipart/alternative;
boundary="Apple-Mail=_0740E365-7FA2-4005-A0DA-DE178055FB8E"
X-Smtp-Server: EC4D00F5-2036-4D28-B425-CB620B245D5E
Subject: Test Mac Mail
Message-Id: <E42C11AE-4BA4-48F5-BA77-0F4A36B70109@shaozi.com>
X-Universally-Unique-Identifier: 4058EBD9-61D0-4E68-82FE-CBDE9E6E3D4F
Date: Tue, 23 Aug 2016 15:34:52 +0800
To: ZhangAo <zhangao@shaozi.com>
Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\))
Date: Tue, 23 Aug 2016 14:54:27 +0800
From: =?utf-8?Q?=E5=BC=A0=E5=A5=A5?= <zhangao@shaozi.com>
To: =?utf-8?Q?=E5=BC=A0=E5=A5=A5?= <zhangao@shaozi.com>
Message-ID: <ec1263ff-5251-4887-95d9-67cdfaf16ded@ZhangAos-MacBook-Pro.local>
Subject: Test
X-Mailer: Shaozi iOS 1.0.5
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="57bbf323_327b23c6_13023"
--57bbf323_327b23c6_13023
@zhangao0086
zhangao0086 / swift_hex.swift
Last active July 28, 2021 22:22
Convert image to hex. NSImage to byte array
// swift
var image = xxx
var rect = NSRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
let cgImage = image.CGImageForProposedRect(&rect, context: nil, hints: nil)!.takeUnretainedValue()
let bitmapRep = NSBitmapImageRep(CGImage: cgImage)
if let imageData = bitmapRep.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: [:]) {
let len = imageData.length
var bytes = [UInt8](count: len, repeatedValue: 0)
@zhangao0086
zhangao0086 / objc_hex.m
Last active August 29, 2015 14:26
Convert image to hex
// Objective-C
UIImage *image = [UIImage imageNamed:<#(NSString *)#>];
NSData *imageData = UIImagePNGRepresentation(image);
NSInteger len = imageData.length;
Byte *bytes = (Byte *)[imageData bytes];
NSMutableString *result = [NSMutableString stringWithCapacity:len * 5];
[result appendString:@"{"];
for (NSUInteger i = 0; i < len; i++) {
if (i) {
[result appendString:@","];