Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
krzyzanowskim / Demangle Swift
Created October 16, 2016 23:20
Hopper Disassembler Swift names demangle script
import subprocess
def looksLikeBeginning(doc,seg,adr):
if isinstance(seg.getNameAtAddress(adr), str):
label = seg.getNameAtAddress(adr)
pos = label.find("_T")
if pos != -1:
return label[pos:]
return None
@aaronjensen
aaronjensen / drain_stop.ex
Last active November 28, 2022 06:59
Phoenix Drain Stop
# ATTENTION: This is now supported in plug_cowboy as of 2.1.0:
# https://hexdocs.pm/plug_cowboy/Plug.Cowboy.Drainer.html
defmodule DrainStop do
@moduledoc """
DrainStop Attempts to gracefully shutdown an endpoint when a normal shutdown
occurs. It first shuts down the acceptor, ensuring that no new requests can be
made. It then waits for all pending requests to complete. If the timeout
expires before this happens, it stops waiting, allowing the supervision tree
to continue its shutdown order.
#!/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -i -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
import Foundation
class JSON {
struct Path: Printable {
enum Element {
case Index(Int)
case Key(String)
// FILED: rdar://17240493
// Type constraint ignored on function type parameter
//
protocol BoolT {}
class TrueT : BoolT {}
class FalseT : BoolT {}
protocol Nat {
typealias IsZero
anonymous
anonymous / Trie.swift
Created June 7, 2014 07:23
//
// Trie.swift
// SceneTest
//
// Created by Greg Titus on 6/7/14.
// Copyright (c) 2014 The Omni Group. All rights reserved.
//
// This is essentially the same data structure as OFTrie in OmniFoundation, except that the OmniFoundation version is mutable and ephemeral,
// and this version is immutable and persistent. Every time you add a string to the trie, it replaces all the nodes along the string's path
@Myuzu
Myuzu / secure_random.ex
Last active August 7, 2022 20:09
Elixir ruby-like SecureRandom
# UPD from 2018:
# This gist was written for pre-1.0 version of Elixir and won't work on post-1.0 versions.
# You probably consider using something else!
defmodule SecureRandom do
@moduledoc """
Ruby-like SecureRandom module.
## Examples
@wbotelhos
wbotelhos / vagrant_cookbook_error.sh
Last active December 19, 2015 00:18
FATAL: NameError: undefined local variable or method `use_inline_resources' for #<Class:0xb709d348>
# If your Chef version is earlier than 11.0.0, use version 1.10.0 of this cookbook: https://github.com/opscode-cookbooks/apt/commit/dd29a85257161ff42c9595627dd370b02be2060f
vagrant halt
cd cookbooks/apt
git reset --hard 1.10.0
vagrant up
@jder
jder / Downscaling ALAssets
Last active March 20, 2018 06:51
A method for downscaling ALAssets
// For details, see http://mindsea.com/2012/12/18/downscaling-huge-alassets-without-fear-of-sigkill
#import <AssetsLibrary/AssetsLibrary.h>
#import <ImageIO/ImageIO.h>
// Helper methods for thumbnailForAsset:maxPixelSize:
static size_t getAssetBytesCallback(void *info, void *buffer, off_t position, size_t count) {
ALAssetRepresentation *rep = (__bridge id)info;
NSError *error = nil;
@etrepum
etrepum / gist:2655724
Created May 10, 2012 20:36
Cowboy graceful acceptor shutdown
-export([graceful_stop/1, graceful_stop_proc/1]).
graceful_stop(Timeout) ->
lists:foreach(fun stop_listener/1, supervisor:which_children(cowboy_sup)),
proc_lib:spawn(?MODULE, graceful_stop_proc, [Timeout]).
graceful_stop_proc(Timeout) ->
true = register(graceful_stop, self()),
lager:critical("SHUTDOWN with timeout of ~p msec", [Timeout]),
TRef = erlang:start_timer(Timeout, self(), not_so_graceful),