Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/osascript
tell application "System Events"
set fusionProcesses to every application process whose bundle identifier is "com.autodesk.fusion360"
repeat with fusionProcess in fusionProcesses
set visible of fusionProcess to false
end repeat
end tell
@liyanage
liyanage / enumerate-lines.m
Created November 13, 2019 04:01
Enumerate lines in a large file with memory mapping through NSData
#import <Foundation/Foundation.h>
typedef void(^LineEnumerator)(NSData *lineData, BOOL *stop);
void enumerateLinesInFileAtURL(NSURL *url, LineEnumerator lineEnumerator) {
NSError *error = nil;
NSData *data = [NSData dataWithContentsOfURL:url options:NSDataReadingMappedAlways error:&error];
if (!data) {
NSLog(@"Unable to open: %@", error);
return;
/*
sudo dtrace -q -p $(pgrep 'Autodesk Fusion 360') -s fusion-360-zoom-trackpad-delay.d
*/
BEGIN
{
eventcounter = 0;
rendercounter = 0;
eventtime = 0;
max_delay = 300;

Keybase proof

I hereby claim:

  • I am liyanage on github.
  • I am liyanage (https://keybase.io/liyanage) on keybase.
  • I have a public key ASCNOzfp-gxK8wRWWMH40CjVTLzpxH_k2FMjehyCaXg46go

To claim this, I am signing this object:

@liyanage
liyanage / gist:6f6379d1f7bffb2bbe1c
Created October 17, 2014 06:21
MicroPython firmware update via DFU on OS X

brew install dfu-util

Download new firmware from http://micropython.org/download/

Connect pins DFU and 3.3v, press reset button

dfu-util -l should list entries with "Found DFU: "

dfu-util --alt 0 --device 0483:df11 -D ~/Desktop/pybv10-2014-10-17-v1.3.3-86-g37ada23.dfu

@liyanage
liyanage / ruby-cheat-sheet.md
Created September 2, 2013 06:52
Ruby cheat sheet

Retry helper

def with_retry(retry_limit=3)
  exception = nil
  retry_limit.times do |i|
    begin
      return yield()
    rescue Exception => ex

print "Attempt #{i + 1} of #{retry_limit} failed: #{ex}\n"

def merge(left, right):
nl = len(left)
nr = len(right)
merged = []
il = 0
ir = 0
while il < nl and ir < nr:
l = left[il]
r = right[ir]
@liyanage
liyanage / gist:4627093
Created January 24, 2013 20:00
Bookmarklet to clean up clutter on infoq.com video viewing web pages.
javascript:$('#rightbar,%20.vendor-content-box,%20#relatedContent,%20#problemsVideo,%20#relatedResearchWidget,%20#header,%20#footer,%20#textlinks').remove()
@liyanage
liyanage / copy_items.py
Created December 14, 2012 07:18
Copy files or directories
import shutil
import os
def copy_item(source_path, destination_parent):
if os.path.isdir(source_path):
destination_path = os.path.join(destination_parent, os.path.basename(source_path))
shutil.copytree(source_path, destination_path, ignore=shutil.ignore_patterns('.DS_Store', '*.pyc'))
else:
shutil.copy(source_path, destination_parent)
@liyanage
liyanage / repr-fallback.py
Created December 1, 2012 02:13
__repr__ implementation handling non-ascii characters.
class Foo:
def __unicode__(self):
return u'xx \u2192 xx'
def __repr__(self):
return unicode(self).encode('ascii', 'backslashreplace')
foo = Foo()