Skip to content

Instantly share code, notes, and snippets.

View dstd's full-sized avatar

Denis Stanishevsky dstd

View GitHub Profile
@dstd
dstd / private.xml
Created November 30, 2014 20:02
karabiner/private.xml backup
<?xml version="1.0"?>
<root>
<item>
<name>Switch layout while holding CapsLock</name>
<appendix>F12 is implied to be configured as layout switch key</appendix>
<identifier>temp.switch.layout.by.capslock</identifier>
<autogen>__KeyToKey__ KeyCode::F19, KeyCode::VK_NONE, Option::KEYTOKEY_BEFORE_KEYDOWN, KeyCode::F12, Option::KEYTOKEY_AFTER_KEYUP, KeyCode::F12</autogen>
</item>
<item>
<name>Right Alt to switch layout</name>
@dstd
dstd / SimpleRawMediaStreamSource.cs
Created April 15, 2015 17:12
With this source the MediaElement.Positions returns values
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace MediaTools
{
@dstd
dstd / inthash.md
Last active August 29, 2015 14:21 — forked from badboy/inthash.md
@dstd
dstd / ViewController.swift
Created October 21, 2015 08:29 — forked from quellish/ViewController.swift
ViewController.swift
import UIKit
import CoreData
import AVFoundation
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, VPDAODelegateProtocol, NSFetchedResultsControllerDelegate {
@IBOutlet weak var segmentedControl: UISegmentedControl!
@IBOutlet weak var tableView: UITableView!
lazy var managedObjectContext : NSManagedObjectContext? = {
@dstd
dstd / gist:b2192efbf9ec56b66d4b
Created December 23, 2015 07:52 — forked from mipmip/gist:1844353
Mac OS X: restart mDNSResponder
Load up Terminal (Applications > Utilities > Terminal.app) and type the following.
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
To turn it back on, just do the opposite:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
@dstd
dstd / Event.kt
Last active February 6, 2016 18:36
Plain simple events source
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) {
@dstd
dstd / Progressive image loading for iOS
Created March 10, 2016 22:37 — 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.
/*
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 / KeyEventHook.kt
Last active June 22, 2016 22:58
KeyEvents interception made via window.callback swizzling
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)
@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 / get_path_true_case.sh
Created February 2, 2017 21:20
Bash function to get correctly-cased path from case insensitive value
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