Skip to content

Instantly share code, notes, and snippets.

QRect desktopRect = QApplication::desktop()->availableGeometry(this);
QPoint center = desktopRect.center();
move(center.x()-width*0.5, center.y()-height*0.5);
import Dispatch
let semaphore = DispatchSemaphore(value: 0)
DispatchQueue.global().asyncAfter(deadline: .now() + 2.0) {
print("I am a delayed call!")
semaphore.signal()
}
@Longhanks
Longhanks / InteractiveTransitionTableViewDeselection.m
Created January 14, 2018 14:42 — forked from smileyborg/InteractiveTransitionCollectionViewDeselection.m
Animate table view deselection alongside interactive transition on iOS 11
/*
In iOS 11, interactive view controller transitions no longer scrub by setting the layer speed to zero
and changing the timeOffset. As a result of this change, implicit animations that occur in places like
-viewWillAppear: (called during an interactive transition) no longer end up “caught in” the animation.
To get the same behavior for table view row deselection as before, you can either use UITableViewController
which implements this for you, or you can implement it manually by deselecting the row in an alongside
animation for the transition (set up in -viewWillAppear: using the transition coordinator).
Here is an example implementation which correctly handles some of the more subtle corner cases:
@Longhanks
Longhanks / capture.py
Created January 15, 2018 10:28
Ekans eval with captured stdout
import sys
from io import StringIO
import contextlib
@contextlib.contextmanager
def stdoutIO(stdout=None):
old = sys.stdout
if stdout is None:
stdout = StringIO()
sys.stdout = stdout
@Longhanks
Longhanks / main.m
Created January 31, 2018 14:29 — forked from jun66j5/main.m
Redirect stdout/stderr to NSLog on iOS Simulator
#include <unistd.h>
static int redirect_nslog(const char *prefix, const char *buffer, int size)
{
NSLog(@"%s (%d bytes): %.*s", prefix, size, size, buffer);
return size;
}
static int stderr_redirect_nslog(void *inFD, const char *buffer, int size)
{
@Longhanks
Longhanks / python_debugging_via_ssh_relay.txt
Last active February 1, 2018 09:10
Python debugging via SSH relay
/etc/ssh/sshd_config:
GatewayPorts yes
Tunnel command:
ssh -R $SSH_RELAY_OPEN_PORT:localhost:$DEBUGGER_PORT $USER@$SSH_RELAY
Python source:
pydevd.settrace('$SSH_RELAY', port=$SSH_RELAY_OPEN_PORT, stdoutToServer=True, stderrToServer=True)
@Longhanks
Longhanks / add_to_reading_list.sh
Created March 30, 2018 21:35
Create reading list item via shell
osascript -l JavaScript -e 'Application("Safari").addReadingListItem("https://www.google.com")'
@Longhanks
Longhanks / fix_native_window.txt
Last active November 11, 2018 03:55
fix_native_window
target_include_directories(<target> PRIVATE ${Qt5Gui_PRIVATE_INCLUDE_DIRS})
Q_DECLARE_METATYPE(QMargins)
#include <qpa/qplatformwindow.h>
#include <qpa/qplatformnativeinterface.h>
QVariant v = qVariantFromValue(QMargins{-8, -30, -8, -8});
native_window->windowHandle()->setProperty("_q_windowsCustomMargins", v);
adobe-source-han-sans-otc-fonts
@Longhanks
Longhanks / userContent.css
Last active August 15, 2022 11:13
userContent.css
code, pre {
font-family: monospace !important;
}
.blob-num, .blob-code, .blob-code-inner {
font-family: monospace !important;
}
.crayon-font-consolas * {
font-family: monospace !important;