Skip to content

Instantly share code, notes, and snippets.

View typoman's full-sized avatar
:electron:
Never stop learning!

Bahman Eslami typoman

:electron:
Never stop learning!
View GitHub Profile
@typoman
typoman / exportRobofontSettings.py
Last active April 8, 2019 15:48
Export Robofont settings to iCloud
from mojo.UI import exportPreferences
import os.path
homeDir = os.path.expanduser("~")
exportPreferences("%s/Library/Mobile Documents/com~apple~CloudDocs/Preferences/Robofont/settings" %homeDir)
{
"cmd": ["robofont", "-p", "$file"],
"file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
"selector": "source.python",
}
@typoman
typoman / RoboFontDefconExample.py
Last active December 17, 2019 19:16
An example to show how to make defcon notifications in RoboFont
from mojo.events import addObserver, removeObserver
from vanilla import Window
class RoboFontDefconExample():
def __init__(self):
self.w = Window((300, 120), "Debuggin window")
self.fonts = {}
for f in AllFonts():
self._addFont(f)
@typoman
typoman / pipenv_virtualenv.py
Created June 8, 2020 19:57 — forked from gxfxyz/pipenv_virtualenv.py
Sublime Text 3 Pipenv virtualenv helper
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Sublime Text 3 Pipenv virtualenv helper.
1. Automatically find and set Pipenv virtualenv for each opened Python file.
- It uses `pipenv --venv` command to find the virtualenv.
- It will add a 'virtualenv' setting, which is the full path to the virtualenv,
@typoman
typoman / overrideRFKeys.py
Created July 31, 2020 13:11
Override RoboFont keys
import AppKit
from vanilla import *
myHotKeys = {'⌘s', '⇧⌘s', '⌘q', '⇧⌘q'}
MODIFIER_INT_TO_STR = {
1048840: '⌘',
262401: '⌃',
524576: '⌥',
131330: '⇧',
@typoman
typoman / pythonTestingUsingUnitTestCheatSheet.md
Created August 19, 2020 17:19
Python Testing Using UnitTest Cheatsheet

Unittest structure

import unittest

class TestAModule(unittest.TestCase):

    def setUp(self):
        # create test data
        pass
@typoman
typoman / osxKeyboardInputSources.py
Last active September 5, 2020 16:16
Finds currently availabe keyboard layout input sources in Mac OSX using pyobjc.
import ctypes
import ctypes.util
import objc
import CoreFoundation
"""
Find currently availabe keyboard layout input sources in Mac OSX using pyobjc. Based on:
https://gist.github.com/tiann/f85e89bef4b6e9b83f2a
"""
@typoman
typoman / simpleRFobserver.py
Created September 7, 2020 20:54
simple objective C observer inside RoboFont
"""
You can use this to get the window name if it has become the key window in
RoboFont. But the same data model can be used to create notifications inside
objc apps.
"""
from objc import python_method
import AppKit
from vanilla import FloatingWindow
from lib.tools.debugTools import ClassNameIncrementer
@typoman
typoman / roboFontPerformanceTests.py
Last active September 8, 2020 10:09
This can be used to find faster ways to perform tasks in RoboFont using python
import time
def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
if 'log_time' in kw:
name = kw.get('log_name', method.__name__.upper())
kw['log_time'][name] = int((te - ts) * 1000)
else:
@typoman
typoman / pythonSimpleRegexLexer.py
Last active April 16, 2021 11:05
Simple Lexer using regex in python
```
import re
from collections import namedtuple
Token = namedtuple('Token', ['type', 'value', 'line', 'column'])
class Lexer(object):
_KEYWORDS = {
'if': 'IF_CONDITION',
'while': 'WHILE_LOOP',