Skip to content

Instantly share code, notes, and snippets.

View drrost's full-sized avatar

Rostyslav Druzhchenko drrost

  • Kharkiv, Ukraine
View GitHub Profile
# Comile the leaker
clang leaker.c -o leaker
# Run leaks detecting tool
leaks -atExit -- ./leaker | grep LEAK:
# Optional
cd /usr/local/lib
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/lib/libLeaksAtExit.dylib
@drrost
drrost / leaker.c
Created April 21, 2020 15:25
A simple example of memory leak
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *p = (char *) malloc(12);
p = 0; // the leak is here
printf("Hello, leak!\n");
return 0;
}
@drrost
drrost / uncrustify.sh
Created April 5, 2020 14:23
Uncrustify setup (C autoformat)
# To `~/.bash_profile`:
emacs ~/.bash_profile
# Add the line:
UNCRUSTIFY_CONFIG="$HOME/.uncrustify"
# Generate a new configuration file:
uncrustify --update-config -o ~/.uncrustify
# Usage
@drrost
drrost / Font+HtmlHeaders.swift
Created February 5, 2020 14:11
HTML notation for Font Swift class
extension Font {
public static let h1: Font = .largeTitle
public static let h2: Font = .title
public static let h3: Font = .headline
public static let h4: Font = .subheadline
public static let h5: Font = .body
public static let h6: Font = .callout
public static let h7: Font = .footnote
public static let h8: Font = .caption
@drrost
drrost / SceneDelegate.swift
Created January 14, 2020 16:12
@EnvironmentObject
//
// SceneDelegate.swift
//
// Created by Rostyslav Druzhchenko on 14.01.2020.
// Copyright © 2020 Rostyslav Druzhchenko. All rights reserved.
//
// Instruction:
//
// 1. Create a sharable class:
// 1. Inherit the class from `ObservableObject`.
@drrost
drrost / Data+Hex.swift
Last active March 11, 2020 12:19
Hexdump Data object to String
import Foundation
private let kHexHeader = "87654321 0011 2233 4455 6677 8899 aabb ccdd eeff 0123456789abcdef\n"
private let kLineHeader = "00000000:"
private let kLineLength = 16
extension Data {
func hexArray() -> String {
extension String {
// MARK: - Substring
private func index(from: Int) -> Index {
self.index(startIndex, offsetBy: from)
}
func substring(from: Int) -> String {
let fromIndex = index(from: from)
extension Date {
private static let isoDateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.timeZone = TimeZone(abbreviation: "GMT")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"
import Foundation
func readVariable(_ name: String) -> String {
if let value = ProcessInfo.processInfo.environment[name] {
return value
}
return ""
}
let homePath = readVariable("HOME")
#!/usr/bin/env swift
import Foundation
@discardableResult
func shell(_ args: String...) -> Int32 {
let task = Process()
task.launchPath = "/usr/bin/env"
task.arguments = args
task.launch()