Skip to content

Instantly share code, notes, and snippets.

View nomeyer's full-sized avatar

Nick Omeyer nomeyer

View GitHub Profile
@nomeyer
nomeyer / combine_queries.sql
Last active March 3, 2016 11:47
Combine queries using the union, intersection, or difference operators (from http://www.postgresql.org/docs/9.4/static/queries-union.html)
(select ... from ...) foo union (select ... from ...) bar;
(select ... from ...) foo intersect (select ... from ...) bar;
(select ... from ...) foo except (select ... from ...) bar;
@nomeyer
nomeyer / electron_sign_mac.sh
Last active March 3, 2016 17:22
Sign an electron Mac app
#!/bin/bash
# Name of your app.
APP="YourApp"
# The path of you app to sign.
APP_PATH="/path/to/YouApp.app"
# The path to the location you want to put the signed package.
RESULT_PATH="~/Desktop/$APP.pkg"
# The name of certificates you requested.
APP_KEY="3rd Party Mac Developer Application: Company Name (APPIDENTITY)"
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { CFMutableDictionaryRef options = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionarySetValue(options, kAXTrustedCheckOptionPrompt, kCFBooleanTrue); AXIsProcessTrustedWithOptions(options); CFRelease(options); }
@nomeyer
nomeyer / child_process_spawn.js
Created February 25, 2016 14:16
Spawn a child process with command line arguments in node.js
const spawn = require('child_process').spawn;
const ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ls.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
ls.on('close', (code) => {
@nomeyer
nomeyer / log_nsstring_c.m
Last active March 26, 2016 17:24
Logging an NSString in c
fprintf(stdout, "%s\n", [str UTF8String]);
fflush(stdout);
@nomeyer
nomeyer / get_focused_window.m
Created February 24, 2016 17:45
Use accessibility to get the focused window of the front most app on OS X
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#include <CoreFoundation/CoreFoundation.h>
NSRunningApplication* frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
pid_t pid = [frontApp processIdentifier];
AXUIElementRef app = AXUIElementCreateApplication(pid);
AXUIElementRef window;
@nomeyer
nomeyer / axerror_print.m
Created February 24, 2016 17:41
If chain to log the outcome (AXError) of an accessibility operation
#include <CoreFoundation/CoreFoundation.h>
AXError rtn = AXUIElementCopyAttributeValue(someApp, someAttribute, (CFTypeRef *)&someRef);
if (rtn == kAXErrorSuccess) {
printf("\nSuccess");
} else if (rtn == kAXErrorInvalidUIElement){
printf("\nInvalid UI Element");
} else if (rtn == kAXErrorIllegalArgument) {
printf("\nIllegal argument");
} else if (rtn == kAXErrorCannotComplete) {
printf("\nCannot complete");
@nomeyer
nomeyer / create_app_from_pid.m
Last active September 4, 2021 18:05
Create an app reference from a PID (accessibility)
#include <CoreFoundation/CoreFoundation.h>
AXUIElementRef app = AXUIElementCreateApplication(pid);
@nomeyer
nomeyer / front_app_pid.m
Last active February 24, 2016 17:38
Get the PID of the frontmost app on Mac OS X
#import <AppKit/AppKit.h>
NSRunningApplication* frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
pid_t pid = [frontApp processIdentifier];
// fprintf(stdout, "%s\n", [[NSString stringWithFormat:@"%ld", (long)pid] UTF8String]);
// fflush(stdout);
@nomeyer
nomeyer / tsne_vis.py
Created February 19, 2016 11:39
Visualise data using the t-SNE algorithm in Python
# Visualise given word embeddings
# words is a list of words
# data is the vector representation of each word
# Train the algorithm
from sklearn.manifold import TSNE
vis_algo = TSNE(random_state=0, verbose=10, init='pca', n_iter=200)
vis = vis_algo.fit_transform(data)
# Plot the resulting visualisation