Skip to content

Instantly share code, notes, and snippets.

View podviaznikov's full-sized avatar
🗽
NYC, hacking, thinking, observing, feeling

anton podviaznikov

🗽
NYC, hacking, thinking, observing, feeling
View GitHub Profile
@kconner
kconner / macOS Internals.md
Last active April 22, 2024 21:28
macOS Internals

macOS Internals

Understand your Mac and iPhone more deeply by tracing the evolution of Mac OS X from prelease to Swift. John Siracusa delivers the details.

Starting Points

How to use this gist

You've got two main options:

extension NSAttributedString {
func highlighting(_ substring: String, using color: UIColor) -> NSAttributedString {
let attributedString = NSMutableAttributedString(attributedString: self)
attributedString.addAttribute(.foregroundColor, value: color, range: (self.string as NSString).range(of: substring))
return attributedString
}
}
// Usage:
@unnamedd
unnamedd / MyService.swift
Created August 8, 2019 13:27 — forked from mminer/MyService.swift
Components of XPC service.
import Foundation
class MyService: NSObject, MyServiceProtocol {
func upperCaseString(_ string: String, withReply reply: @escaping (String) -> Void) {
let response = string.uppercased()
reply(response)
}
}
@unnamedd
unnamedd / MacEditorTextView.swift
Last active April 16, 2024 10:18
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
@mfikes
mfikes / README.md
Last active September 24, 2023 13:15
eval in ClojureScript

ClojureScript master now has cljs.core/eval. This delegates to cljs.core/*eval* which, by default throws, but you can bind it to any implementation that can compile and evaluate ClojureScript forms.

If you require the cljs.js namespace (which is the main support namespace for self-hosted ClojureScript), then cljs.core/*eval* is set to an implementation that uses self-hosted ClojureScript for this capability. This means that all self-hosted ClojureScript environments will now have a first-class eval implementation that just works. For example, Planck master:

$ planck -q
cljs.user=> (eval '(+ 2 3))
5
@enricofoltran
enricofoltran / main.go
Last active April 1, 2024 00:17
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"

Synopsis

Problem: Omegawiki's database layout ( http://www.omegawiki.org/Help:OmegaWiki_database_layout ) is incredibly complex and makes it tough to query the db.

This quick'n'dirty script imports the data into datomic. It aims to fully connect them with refs so that you can walk along the entities just like clojure maps.

Once in Datomic the entire db is in memory and it's very easy to explore the db and also very fast.

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@EvanLovely
EvanLovely / get_title_and_url.applescript
Created March 28, 2017 00:26 — forked from vitorgalvao/Get Title and URL.applescript
AppleScript and JavaScript for Automation to get frontmost tab’s url and title of various browsers.
-- AppleScript --
-- This example is meant as a simple starting point to show how to get the information in the simplest available way.
-- Keep in mind that when asking for a `return` after another, only the first one will be output.
-- This method is as good as its JXA counterpart.
-- Google Chrome
tell application "Google Chrome" to return title of active tab of front window
tell application "Google Chrome" to return URL of active tab of front window
-- Google Chrome Canary
@vjk2005
vjk2005 / automator_jquery.txt
Created March 2, 2017 06:23
Inject jquery into the most active tab using JXA (Javascript for Automation, OSX)
// put this inside a Run Javascript block in Automator
app.doJavaScript("var script = document.createElement('script'); script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js'; document.getElementsByTagName('head')[0].appendChild(script);", {
in: app.windows[0].currentTab
})
delay(1); // wait for jQuery to load
//... jQuery is now loaded, now add the rest of the script