Skip to content

Instantly share code, notes, and snippets.

View MainasuK's full-sized avatar

CMK MainasuK

View GitHub Profile
@MainasuK
MainasuK / Change self-size cell row height
Last active July 20, 2016 02:29
iOS Tips: Change table view cell row height
// If you use self-size cell with stack view or Auto Layout.
// Try this to change row height with animation
// Assume you set the content heightConstraint which group in your stack view
// Or other heightConstraint to make your cell self-size
func changeRowHeight(in tableView: UITableView, at indexPath: IndexPath, with height: CGFloat) {
tableView.beginUpdates()
// Change your cell heightConstraint height
@MainasuK
MainasuK / List.swift
Last active August 25, 2016 17:39
List: Collection
//: The up to date code snippet (Xcode 8 beta 6) for List which comforms Collection — *Advanced Swift*
import UIKit
private enum ListNode<Element> {
case end
indirect case node(Element, next: ListNode<Element>)
func cons(x: Element) -> ListNode<Element> {
return .node(x, next: self)
@MainasuK
MainasuK / CommodityClassificationInformationManagementController.java
Last active July 10, 2023 17:23
Add checkbox cell to tableView - JavaFX 8 with lambda
TableView<T> tableView;
TableColumn<T, Boolean> booleanColumn;
private void setupTableView() {
tableView.setEditable(true);
}
private void setupTableViewColumn() {
booleanColumn.setCellFactory(column -> new CheckBoxTableCell<>());
booleanColumn.setCellValueFactory(cellData -> {
@MainasuK
MainasuK / RSA.java
Created May 16, 2017 09:00
Simple RSA demo for learning purpose.
import java.io.*;
import java.math.BigInteger;
import java.security.SecureRandom;
/**
* Created by MainasuK on 2017-5-9.
*/
public class RSA {
// public key
import Vapor
import Glibc
extension Droplet {
func setupRoutes() throws {
get("hello") { req in
var json = JSON()
try json.set("hello", "world")
return json
}
@MainasuK
MainasuK / doc2pdf_simple.py
Created August 25, 2017 11:29
Save apple document as PDF (Simple Version)
import requests
import pdfkit
from bs4 import BeautifulSoup
url = 'https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/SafariAppExtension_PG/index.html'
pdfkit.from_url(url, 'out.pdf')
@MainasuK
MainasuK / APDPS.py
Created August 28, 2017 00:02
Apple document pages spider
import requests
import sys
from bs4 import BeautifulSoup
from sys import stdin
# usage:
# echo 'https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/SafariAppExtension_PG/index.html' | python3 document_urls.py
# Use this script get link of pages for *one* apple programming guide document
@MainasuK
MainasuK / download_events_parallel.swift
Created January 23, 2018 11:25
RxSwift parallel downloading demo
func startDownload() {
let eoCategories = EONET.categories
let downloadedEvents = eoCategories.flatMap { categories in
return Observable.from(categories.map { category in
EONET.events(forLast: 360, category: category)
})
}
.merge(maxConcurrent: 2)
let updatedCategories = eoCategories.flatMap { categories in
[
{
"address": "0x4E84E9e5fb0A972628Cf4568c403167EF1D40431",
"symbol": "$FFC",
"decimal": 18,
"type": "default"
},
{
"address": "0xa024e8057eec474a9b2356833707dd0579e26ef3",
"symbol": "$FYX",

It often be helpful to be able to debug memory usage in Swift on Linux, for example to debug memory leaks.

This is a quick overview of how to generate a report of memory usage for your Swift app. This guide will only show you how to generate the report, not how to analyze it, it might be written up in a blog post later.

Install Valgrind

First we need to install a tool called Valgrind, which is used to trace memory usage.