Skip to content

Instantly share code, notes, and snippets.

View orklann's full-sized avatar
🏠
Working from home

rkt orklann

🏠
Working from home
View GitHub Profile
@orklann
orklann / brew-perms.sh
Created May 24, 2021 12:47 — 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.
#!/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
"""
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 12:53 — forked from jeffkreeftmeijer/XmlParser.h
Objective-C XML parser
#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 February 27, 2021 03:52 — forked from dongyuwei/get_title_and_url.applescript
Applescript to get frontmost tab’s url and title of various browsers.
# 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 February 17, 2021 09:02
Old method of getting glyph advance
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 February 16, 2021 06:36
Old draw string method
/* == 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 December 26, 2020 08:47 — forked from kaishin/snapshot.swift
NSView Snapshot
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 November 19, 2020 06:49
Get all font families and its family members
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 October 30, 2020 02:23
PEP: GMisc: isWordBreaks(); GTextParser: makeWords
// 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 October 21, 2020 07:12 — forked from Bokugene/CGFontToFontData.m
Read Table Data from a CGFont, then wrap them into a OTF/TTF font.
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;