Skip to content

Instantly share code, notes, and snippets.

View gavrix's full-sized avatar
:shipit:
Shipping

Sergey Gavrilyuk gavrix

:shipit:
Shipping
  • Shopify
  • Toronto, ON
View GitHub Profile
@gavrix
gavrix / chalk_nanocolors_transform.js
Last active September 27, 2021 02:24
codemod to migrate chalk => nanocolors
module.exports = function(fileInfo, api, options) {
const j = api.jscodeshift
const root = j(fileInfo.source)
var usedMethods = new Set()
const chalkImport = root.find(j.ImportDeclaration, {
source: {
pcm.!default {
type plug
slave.pcm {
type dmix
ipc_key 1024
slave {
pcm "plughw:0,0"
rate 48000 # this line is only needed for USB DACs which only support 48khz
period_time 0
period_size 1920
@interface NSString (ss)
- (NSString *):(NSString *)str;
@end
@implementation NSString (ss)
- (NSString *):(NSString *)str {
return [NSString stringWithFormat:self, str];
}
@end
enum EndPoints {
case GetUser
case UpdateUser(userData: User)
}
extension ParseEndpoints: HTTPEndPointConvertible, HTTPEndPointDSL {
func toHTTPEndPoint() -> HTTPEndPoint {
let baseURL = "https://api.parse.com/1"
switch (self) {
@gavrix
gavrix / gist:10488144
Last active August 29, 2015 13:59
Is it crazy?
((void (^)())@[
^{[self action2];},
^{[self action1];} ][value.boolValue])();
//vs
if (value.booldValue) {
[self action1];
}
@gavrix
gavrix / gist:8961770
Last active August 29, 2015 13:56
objc NSDictionary literals vs c-style switch
NSInteger sourceIntValue;
id mappedValue = (@{@(kSomeConstValue1): KSomeConstMappedValue1,
@(kSomeConstValue2): KSomeConstMappedValue2}[@(sourceIntValue)])?:KSomeConstMappedDefaultValue;
//VS
id mappedValue;
switch(sourceIntValue) {
case kSomeConstValue1:
@interface UIScrollView (willBeginScrollingAnimation)
@end
@implementation UIScrollView (willBeginScrollingAnimation)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-method-access"
+(void)load {
Method setContentOffsetAnimatedMethod = class_getInstanceMethod([UIScrollView class], @selector(setContentOffset:animated:));
IMP oldImplementation = method_getImplementation(setContentOffsetAnimatedMethod);
@gavrix
gavrix / gist:5054182
Created February 28, 2013 04:28
Script integrating OCLint into XCode. Put it in "Run script" build phase.
source ~/.bash_profile
hash oclint &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "oclint not found, analyzing stopped"
exit 1
fi
@gavrix
gavrix / NSArray+first.h
Created September 13, 2012 13:38
-firstObject
@interface NSArray (addition)
-(id) firstObject;
@end