Skip to content

Instantly share code, notes, and snippets.

@cybercase
cybercase / gptactions.js
Created April 27, 2024 16:34
A Mac Automation Script to run OpenAI GPTs over selected text
/*
# A Mac Automation Script to run OpenAI GPTs over selected text.
Copy this script into your home directory, then:
1. Set the OPENAI_API_KEY variable in the script
2. Open the Automator app on your Mac and Create a new "Quick Action" workflow.
3. Set the workflow to receive "text" in "any application".
4. Add a "Run Shell Script" action.
5. Copy and paste the following command into the script box:
cat ~/gptactions.js | osascript -l JavaScript - $(cat)
@cybercase
cybercase / CustomWindow.swift
Last active July 12, 2018 15:21
Debug responder chain in Cocoa
class CustomWindow: NSWindow {
override init(contentRect: NSRect, styleMask style: NSWindow.StyleMask, backing backingStoreType: NSWindow.BackingStoreType, defer flag: Bool) {
super.init(contentRect: contentRect, styleMask: style, backing: backingStoreType, defer: flag)
}
override func makeFirstResponder(_ responder: NSResponder?) -> Bool {
self.printResponderChain(responder)
return super.makeFirstResponder(responder)
}
@cybercase
cybercase / Prop.swift
Last active August 6, 2017 12:39
While waiting for swift4 observe method
//
// Prop.swift
// GQLC
//
// Created by Stefano Brilli on 01/08/2017.
// Copyright © 2017 Stefano Brilli. All rights reserved.
//
import Cocoa
@cybercase
cybercase / gist:746c9ce836e53b50944b
Created November 28, 2014 17:16
Removes all docker containers
docker ps -a | cut -c-12 | xargs docker rm
@cybercase
cybercase / product.js
Last active February 10, 2023 10:59
Python-like itertools.product function in javascript
function product() {
var args = Array.prototype.slice.call(arguments); // makes array from arguments
return args.reduce(function tl (accumulator, value) {
var tmp = [];
accumulator.forEach(function (a0) {
value.forEach(function (a1) {
tmp.push(a0.concat(a1));
});
});
return tmp;
@cybercase
cybercase / string-format.js
Created August 20, 2014 10:23
Python-like .format method for javascript String
// Original: http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format
// Edited: cybercase
if (!String.prototype.format) {
String.prototype.format = function(dict) {
return this.replace(/{(\w+)}/g, function(match, key) {
return typeof dict[key] !== 'undefined'
? dict[key]
: match
;
@cybercase
cybercase / dns.py
Last active August 9, 2017 11:55
Simple (and limited) DNS query client
#!/usr/bin/env python
# -*- coding:utf8 -*-
import random
import socket
import struct
import StringIO
import argparse
from collections import namedtuple
MAX_PACKET_SIZE = 512
@cybercase
cybercase / gist:7928380
Created December 12, 2013 14:02
Django Shell SQL debug query logging verbose
import logging
l = logging.getLogger('django.db.backends')
l.setLevel(logging.DEBUG)
l.addHandler(logging.StreamHandler())