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 / keystroke-toggle-linenumbers-settings.json
Created July 15, 2021 13:09 — forked from pid/keystroke-toggle-linenumbers-settings.json
Sublime Text keystroke toggle line numbers show/hide
{
"keys": ["ctrl+alt+l"],
"command": "toggle_setting",
"args": {
"setting": "line_numbers"
}
@orklann
orklann / rw_flash.py
Last active June 18, 2021 07:44
Meowbit read and write Flash
from meowbit import screen
from meowbit import pyb
fl = pyb.Flash()
# Doc:
# 1. https://docs.micropython.org/en/latest/library/pyb.Flash.html#pyb-flash
# 2. https://docs.micropython.org/en/latest/reference/filesystem.html#stm32-pyboard
# 4000th blocks to read and write, as Meowbit has 2MB flash size,
@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]);