Skip to content

Instantly share code, notes, and snippets.

@dstd
dstd / input_source_switch.json
Last active Nov 30, 2020
Input language switching mods for Karabiner
View input_source_switch.json
{
"title":"Input source change",
"rules": [
{
"description": "If pressed alone, CmdL for English, CmdR for Russian",
"manipulators": [
{
"from": {
"key_code": "left_command",
"modifiers": {"optional": ["any"]}
@dstd
dstd / git_find_file_in_history.sh
Created Jan 30, 2019
Find specific file in GIT history
View git_find_file_in_history.sh
#!/usr/bin/env bash
# Find specific file in GIT history
if [ "$1" = "" ]; then
echo "Usage: ./$(basename ${0}) file" && exit 1
fi
_file=$1
blob=`git hash-object $_file`
@dstd
dstd / customrules.js
Created Feb 27, 2018
[Fiddler] JSON response modification
View customrules.js
// ...
static function OnBeforeResponse(oSession: Session) {
// ...
if (oSession.uriContains("/someMethod")) {
var json = Fiddler.WebFormats.JSON.JsonDecode(oSession.GetResponseBodyAsString()).JSONObject;
var p = json["field"]["subfield"]["subsubfield"];
p["field1"] = 0 != 1;
p["anotherfield2"] = 0 != 0;
p["yaf3"] = 0 != 1;
@dstd
dstd / customrules.js
Last active Feb 27, 2018
[Fiddler] Sessions coloring
View customrules.js
// ...
static function OnBeforeRequest(oSession: Session) {
// ...
var clientColors = ["red", "blue", "green", "gold", "orange", "purple"];
var clientId = oSession.oRequest.headers["User-Agent"] + oSession.oRequest.headers["Authorization"];
oSession["ui-color"] = clientColors[Math.abs(clientId.GetHashCode()) % clientColors.length];
// ...
}
// ...
@dstd
dstd / get_path_true_case.sh
Created Feb 2, 2017
Bash function to get correctly-cased path from case insensitive value
View get_path_true_case.sh
get_path_true_case()
{
local C_PATH="/"
local C=""
local OLD_IFS="$IFS"
IFS=/
for C in $1; do
if [ "$C_PATH" = "/" ]; then
C_PATH=`find "$C_PATH" -maxdepth 1 -type d -ipath "$C_PATH$C"`
else
@dstd
dstd / DownloadTaskRequest.kt.diff
Last active Feb 19, 2020
[Fuel library] patch to support payload streaming in uploading/downloading
View DownloadTaskRequest.kt.diff
diff --git a/kittinunf/fuel/core/requests/DownloadTaskRequest.kt b/kittinunf/fuel/core/requests/DownloadTaskRequest.kt
index d64d331..adfab9b 100755
--- a/kittinunf/fuel/core/requests/DownloadTaskRequest.kt
+++ b/kittinunf/fuel/core/requests/DownloadTaskRequest.kt
@@ -11,8 +11,8 @@ import java.net.URL
class DownloadTaskRequest(request: Request) : TaskRequest(request) {
- val BUFFER_SIZE = 1024
-
- var progressCallback: ((Long, Long) -> Unit)? = null
- lateinit var destinationCallback: ((Response, URL) -> File)
View src » deploy » ConnectionInspector.kt
@file:Suppress("UNUSED_PARAMETER", "NOTHING_TO_INLINE") // it's a stub for ConnectionInspector so just suppress the warnings
import java.io.IOException
import java.io.InputStream
import java.net.HttpURLConnection
class ConnectionInspector(friendlyName: String?) {
inline fun preConnect(connection: HttpURLConnection, requestEntity: ByteArray?) = Unit
inline fun postConnect() = Unit
inline fun interpretResponseStream(responseStream: InputStream?): InputStream? = responseStream
@dstd
dstd / KeyEventHook.kt
Last active Jun 22, 2016
KeyEvents interception made via window.callback swizzling
View KeyEventHook.kt
class KeyEventHook private constructor(
private val window: Window,
private val handleKeyEvent: (KeyEvent) -> Boolean,
private var originalCallback: Window.Callback)
: Window.Callback by originalCallback
{
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
if (handleKeyEvent(event))
return true
return originalCallback.dispatchKeyEvent(event)
@dstd
dstd / Progressive image loading for iOS
Created Mar 10, 2016 — forked from foundry/Progressive image loading for iOS
Progressive image loading for iOS. This is a GIST - detailed implementation is left as an exercise for the reader.
View Progressive image loading for iOS
/*
typical usage (FYImageStore is a singleton)
[[FYImageStore instance] retrieveFullsizeImageFromPath:path
completion:^(UIImage* image){
self.imageView.image = image
}];
*/
#import "FYImageURL.h" //URL-building utilities, omitted from this Gist.
@dstd
dstd / Event.kt
Last active Feb 6, 2016
Plain simple events source
View Event.kt
import java.util.*
import kotlin.Int
import kotlin.Int as ObserverId
class Event<T>() {
private val listeners: MutableMap<Int, (T) -> Unit> = HashMap();
private var nextListenerId: Int = 0
fun observe(listener: (T) -> Unit): ObserverId {
synchronized(this.listeners) {