Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Crafting stuff

rkt orklann

💭
Crafting stuff
View GitHub Profile
@orklann
orklann / brew-perms.sh
Created May 24, 2021 — forked from jaibeee/brew-perms.sh
Configure homebrew permissions to allow multiple users on MAC OSX. Any user from the admin group will be able to manage the homebrew and cask installation on the machine.
View brew-perms.sh
#!/bin/sh
# Configure homebrew permissions to allow multiple users on MAC OSX.
# Any user from the admin group will be able to manage the homebrew and cask installation on the machine.
# allow admins to manage homebrew's local install directory
chgrp -R admin /usr/local
chmod -R g+w /usr/local
# allow admins to homebrew's local cache of formulae and source files
chgrp -R admin /Library/Caches/Homebrew
View mock_image_processing.py
"""
1. Store the image and create an instance of ImagefileProcessHistory with status NOT_STARTED
ImageFileProcessHistory
- local_path
- file_name
- status # enum: NOT_STARTED, STARTED, SUCCEEDED, FAILED
- bytes_processed
- bytes_total
"""
@orklann
orklann / XmlParser.h
Created May 5, 2021 — forked from jeffkreeftmeijer/XmlParser.h
Objective-C XML parser
View XmlParser.h
#import <Foundation/Foundation.h>
@interface XmlParser : NSObject <NSXMLParserDelegate>
@property (strong, nonatomic) NSData *xmlData;
@property (strong, nonatomic) NSMutableDictionary *dictionary;
@property (strong, nonatomic) NSMutableDictionary *currentNode;
@property (strong, nonatomic) NSMutableDictionary *currentParentNode;
- (id)initWithXMLData:(NSData *)xmlData;
@orklann
orklann / get_title_and_url.applescript
Created Feb 27, 2021 — forked from dongyuwei/get_title_and_url.applescript
Applescript to get frontmost tab’s url and title of various browsers.
View get_title_and_url.applescript
# Keep in mind that when asking for a `return` after another, only the first one will be output.
# This example is meant as a simple starting point, to show how to get the information in the simplest available way.
# Google Chrome
tell application "Google Chrome" to return URL of active tab of front window
tell application "Google Chrome" to return title of active tab of front window
# Google Chrome Canary
tell application "Google Chrome Canary" to return URL of active tab of front window
tell application "Google Chrome Canary" to return title of active tab of front window
# Chromium
@orklann
orklann / glyph_advance.m
Created Feb 17, 2021
Old method of getting glyph advance
View glyph_advance.m
CGFloat getGlyphAdvanceForFont(NSString *ch, NSFont *font) {
// Handle tab character width, because it's not correct to get it with
// CTRunGetAdvances().
if ([ch isEqualToString:@"\t"]) {
// NOTE: (TAB) This clause will never reach because when a \t is entered,
// We convert it into a ' '.
// But I will leave this code her for alternative method to
// get glyph width
CGRect rect;
CGFontRef cgFont = CTFontCopyGraphicsFont((CTFontRef)font, nil);
@orklann
orklann / draw_string.m
Created Feb 16, 2021
Old draw string method
View draw_string.m
/* == Old draw string method
*/
- (CGFloat)drawString:(NSString*)ch font:(NSFont*)font context:(CGContextRef)context {
NSMutableAttributedString *s = [[NSMutableAttributedString alloc] initWithString:ch];
[s addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, 1)];
[s addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, 1)];
CFAttributedStringRef attrStr = (__bridge CFAttributedStringRef)(s);
CTLineRef line = CTLineCreateWithAttributedString(attrStr);
CTLineDraw(line, context);
@orklann
orklann / snapshot.swift
Created Dec 26, 2020 — forked from kaishin/snapshot.swift
NSView Snapshot
View snapshot.swift
extension NSView {
var snapshot: NSImage {
guard let bitmapRep = bitmapImageRepForCachingDisplayInRect(bounds) else { return NSImage() }
bitmapRep.size = bounds.size
cacheDisplayInRect(bounds, toBitmapImageRep: bitmapRep)
let image = NSImage(size: bounds.size)
image.addRepresentation(bitmapRep)
return image
}
}
@orklann
orklann / font_families.m
Created Nov 19, 2020
Get all font families and its family members
View font_families.m
NSFontManager *fm = [NSFontManager sharedFontManager];
NSArray *fontFamilies = [fm availableFontFamilies];
int i;
for (i = 0; i < [fontFamilies count]; i++){
NSArray *familyMembers;
familyMembers = [fm availableMembersOfFontFamily:
[fontFamilies objectAtIndex: i]];
int j = 0;
for (j = 0; j < [familyMembers count]; j++) {
NSLog(@"%@", [familyMembers objectAtIndex: j]);
@orklann
orklann / .m
Created Oct 30, 2020
PEP: GMisc: isWordBreaks(); GTextParser: makeWords
View .m
// Check if two glyphs mark a word break, function like a white space
// GMisc.m
BOOL isWordBreaks(GGlyph *a, GGlyph *b) {
if (a == nil || b == nil) {
BOOL result = NO;
//NSLog(@"Nil case cur: %@ next: %@ result: %d", [a content], [b content], result);
return result;
}
NSRect f1 = [a frame];
@orklann
orklann / CGFontToFontData.m
Created Oct 21, 2020 — forked from Jyczeal/CGFontToFontData.m
Read Table Data from a CGFont, then wrap them into a OTF/TTF font.
View CGFontToFontData.m
typedef struct FontHeader {
int32_t fVersion;
uint16_t fNumTables;
uint16_t fSearchRange;
uint16_t fEntrySelector;
uint16_t fRangeShift;
}FontHeader;
typedef struct TableEntry {
uint32_t fTag;