Skip to content

Instantly share code, notes, and snippets.

@nicoster
nicoster / onwificonnect.mm
Last active April 13, 2023 02:59
invoke a script when wifi connection changes. it will hold the notification for 5 seconds and coalesce repeating notifications.
#import <Foundation/Foundation.h>
#include <CoreFoundation/CoreFoundation.h>
void onNotifyCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
NSString* notifyName = (NSString*)name;
if ([notifyName isEqualToString:@"com.apple.system.config.network_change"]) {
// Get the path to the shell script from the command line
NSArray *arguments = [[NSProcessInfo processInfo] arguments];
if (arguments.count > 1) {
NSString *shellScriptPath = [arguments objectAtIndex:1];
@nicoster
nicoster / screenres.swift
Last active November 28, 2022 02:41 — forked from jminor/screenres.swift
Change your Mac's screen resolution from the command line.
#!/usr/bin/swift
// fix build errors with Swift 5.
// Known issues: some resolution is not HiDPI
import Foundation
var shouldPrintUsage = true
var shouldPrintModes = true
var shouldSwitchMode = false
local ins = require 'inspect'
local function insert_prioq(prioq, el, freq, insert_after)
for i, v in ipairs(prioq) do
-- print('i:', i, ' v:', ins(v))
if insert_after then
if freq < v[2] then
table.insert(prioq, i, {el, freq})
-- print(ins(prioq))
@nicoster
nicoster / gitlabcli
Last active January 3, 2018 14:04
to make gitlab admin life easier.
#!/usr/bin/env python3
import requests as httpc
import sys
import json
'''
API reference:
. https://docs.gitlab.com/ee/api/members.html#edit-a-member-of-a-group-or-project
. https://docs.gitlab.com/ce/api/projects.html#list-all-projects
@nicoster
nicoster / otp-commands.gdb
Last active January 19, 2017 13:32
erts/etc/unix/etp-commands.in. print LP64 correctly. show HeapBinary directly
#
# %CopyrightBegin%
#
# Copyright Ericsson AB 2005-2014. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@nicoster
nicoster / beam.md
Created February 26, 2016 04:24 — forked from studzien/beam.md
An example analysis of a BEAM process core dump

This post shows an example of a BEAM process' core dump analysis to backtrack what was the root cause of its crash.

Start gdb by pointing out the BEAM executable that generated the core dump and the core dump file. Optionally, you can provide a directory with the VM's source code:

gdb erts-6.3/bin/beam.smp -core core.14747 -d /home/azureuser/otp_src_17.4/erts/emulator

gdb should tell you what caused the crash and where in code this happened:

@nicoster
nicoster / softokend.js
Created June 13, 2014 11:04
turn SofToken II.app into a https web service
#!/usr/bin/env node
// the pathname of the url without the leading '/' is used as softoken pin
// so make the call with http://localhost:8000/<softoken-pin>
const https = require('https'),
fs = require("fs"),
url = require('url'),
exec = require('child_process').exec;
@nicoster
nicoster / c++.sublime-build
Created February 24, 2014 06:41
This is the custom sublime-build for c++ that works for me the best. pay attention to the 'selector' field. it's a plain string rather than an array. keyword: vs2008, cl.exe, sublime text, custome build
{
"cmd": ["cl", "${file}", "/link", "user32.lib"],
"path": "C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Common7\\IDE;C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\BIN;C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Common7\\Tools;C:\\Windows\\Microsoft.NET\\Framework\\v3.5;C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727;C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\VCPackages;C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\bin;C:\\Program Files\\Intel\\iCLS Client\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0;C:\\Program Files\\TortoiseSVN\\bin;c:\\python27;C:\\Python27\\Scripts;c:\\program files\\bin;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Chocolatey\\bin;",
"working_dir": "${file_path:${folder}}",
"file_regex": "^\\s*(.+?)\\(([0-9]+),?([0-9]+)?\\):\\s*(.*) \\[",
"shell": true,
"selector": "s
#include <mach/mach.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#define CHECK_MACH_ERROR(a, msg) do {kern_return_t rr = (a); if ((rr) != KERN_SUCCESS) { printf("%s Mach error %x (%s) on line %d of file %s\n", msg, (rr), mach_error_string((rr)), __LINE__, __FILE__); abort(); } } while (0)
static int
setup_recv_port (mach_port_t *recv_port)
@nicoster
nicoster / .slate.js
Last active January 2, 2016 05:19
my slate config file
/*
my slate config file
nicoster@gmail
*/
function hyper(key){return key + ':ctrl;shift;alt;cmd';}
slate.bind(hyper('r'), slate.op('relaunch'));
// fast switch to common applications