Skip to content

Instantly share code, notes, and snippets.

View k06a's full-sized avatar
🚀
DeFi dreamer

Anton Bukov k06a

🚀
DeFi dreamer
View GitHub Profile
@danielnorton
danielnorton / AttributedRoundtrip.m
Last active August 9, 2016 13:56
Unexpected roundtrip of HTML through NSAttributedString. This demonstrates a simple HTML file going into an NSAttributedString and then writing that string back out to a new HTML file. The output file is structured very differently than the input file. This was discovered while experimenting with using a UITextView as a rich text editor.
- (NSAttributedString *)loadContent {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"input" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
NSDictionary *options = @{
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)
};
@mikeash
mikeash / runtime-class.m
Created November 22, 2013 16:46
Creating a usable class purely at runtime using the Objective-C runtime APIs.
// clang -fobjc-arc -framework Foundation runtime-class.m
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface Person : NSObject
- (id)initWithFirstName: (NSString *)firstName lastName: (NSString *)lastName age: (NSUInteger)age;
@steipete
steipete / CaseInsensitiveDictionary.m
Created December 1, 2013 19:12
Implemented as a category on NSDictionary.
static Boolean PSPDFCaseInsensitiveEqualCallback(const void *a, const void *b) {
id objA = (__bridge id)a, objB = (__bridge id)b;
Boolean ret = FALSE;
if ([objA isKindOfClass:NSString.class] && [objB isKindOfClass:NSString.class]) {
ret = ([objA compare:objB options:NSCaseInsensitiveSearch|NSLiteralSearch] == NSOrderedSame);
}else {
ret = [objA isEqual:objB];
}
return ret;
}
@aras-p
aras-p / lambda.cpp
Last active September 24, 2019 02:40
Lambda art
// C++11 lambdas aren't terribly useful at producing art.
// Source below is valid C++11. VS2013 takes about a minute at it (Release config),
// reaches almost 4GB of memory usage and then gives a
//
// 1>ConsoleApplication1.cpp(34): fatal error C1001: An internal error has occurred in the compiler.
// 1> (compiler file 'msc1.cpp', line 1325)
// 1> To work around this problem, try simplifying or changing the program near the locations listed above.
// 1> Please choose the Technical Support command on the Visual C++
// 1> Help menu, or open the Technical Support help file for more information
// 1> This error occurred in injected text:
@chrismccoy
chrismccoy / gitcheats.txt
Last active February 27, 2025 15:51
git cheats
# alias to edit commit messages without using rebase interactive
# example: git reword commithash message
reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"
# aliases to change a git repo from private to public, and public to private using gh-cli
alias gitpublic="gh repo edit --accept-visibility-change-consequences --visibility public"
alias gitprivate="gh repo edit --accept-visibility-change-consequences --visibility private"
# delete all your repos using gh-cli (please do not run this unless you want to delete all your repos)
gh repo list --limit 300 --json url -q '.[].url' | xargs -n1 gh repo delete --yes
@timsutton
timsutton / auto-update-mas-apps.sh
Last active March 7, 2018 06:54
Clear storeagent cache and trigger Mac App Store app updates.
#!/bin/sh
#
# Trigger an update of MAS (and softwareupdate) apps
#
# This seems to be all that's needed to schedule an immediate update of
# MAS apps. This should be run as a normal user. You can run this and
# tail the install log to get an idea of what's happening.
#
# You can also take a look at this user's ~/Library/Caches/com.apple.storagent
# directory to get a report on what apps were available, installable, etc.
@EmielM
EmielM / uiwebview-tweaks.m
Created May 8, 2014 18:31
UIWebview enhancement hacks
// Continuously changing GIST of UIWebView 'tweaks' I use. Might be useful to others,
// hope Google finds this. Some of these already passed Review, but one never knows ;).
// Happy coding!
- (void)ScrollView_setContentOffset:(CGPoint)offset {
// Prevent superfluous scrolling animations (eg when toggling keyboard) by completely disabling scrolling. We achieve scrolling through inner scroll views (overflowing html elements).
}
- (id)WebBrowserView_inputAccessoryView {
// Make the keyboard accessory view (next/prev,submit buttons) optional, it really takes up to much screen estate in a normal app.
@venkatperi
venkatperi / gist:209b9fa2946a7151efc0
Created June 4, 2014 15:53
Closure Currying in Swift
struct S0<V> {
typealias F = () -> V
}
struct S1<T1,V>{
typealias F = (T1) -> V
}
//0, 0
func curry<T1, V>(f: S1<T1, V>.F, a1:T1) -> S0<V>.F {
@bsweger
bsweger / useful_pandas_snippets.md
Last active April 4, 2025 21:20
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@claybridges
claybridges / gist:c289d5fa6e3e386e8921
Last active November 15, 2023 18:10
Use rvm in a shell script
#!/usr/bin/env bash
# Xcode scripting does not invoke rvm. To get the correct ruby,
# we must invoke rvm manually. This requires loading the rvm
# *shell function*, which can manipulate the active shell-script
# environment.
# cf. http://rvm.io/workflow/scripting
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then