Skip to content

Instantly share code, notes, and snippets.

@Air-Craft
Air-Craft / Contract Killer 3.md
Created February 3, 2020 10:22
The latest version of my ‘killer contract’ for web designers and developers

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Original post

@Air-Craft
Air-Craft / ffmpeg_from_m3u_stream.sh
Created December 24, 2015 13:29
Rip m3u8 stream (series of .ts files) to video via ffmpeg #video #conversion #streaming #ripping
ffmpeg -i "https://content.jwplatform.com/manifests/Wqyolfwt.m3u8" -c copy -bsf:a aac_adtstoasc video.mp4
@Air-Craft
Air-Craft / flush_memcache.sh
Created June 28, 2015 13:12
Flush memcache server from command line #CLI #memcache #bash
echo 'flush_all' | nc localhost 11211
# Or...
nc 192.168.1.10 11211<<<"flush_all"
@Air-Craft
Air-Craft / cifilter_calayer.m
Created April 30, 2015 09:36
Apply CIFilter to a CALayer #CoreImage #image-manipulation #ios
// SIMPLE
// Note: Can convert to UIImage but there's no way to go to CGImage.
CIImage *newImg = [[CIImage imageWithCGImage:img.CGImage] imageByApplyingFilter:@"CIColorMonochrome"
withInputParameters:@{kCIInputColorKey: ciCol}];
// EXTENDED
CIContext *ctx = [CIContext contextWithOptions:nil];
CIFilter *filter = [CIFilter filterWithName:@"CIColorMonochrome"];
@Air-Craft
Air-Craft / iphone_vibrate.m
Created April 26, 2015 13:55
Short custom vibration on iPhone #ios #vibration #private-api
// Headers
#import <AudioToolbox/AudioToolbox.h>
void AudioServicesStopSystemSound(SystemSoundID inSystemSoundID);
void AudioServicesPlaySystemSoundWithVibration(SystemSoundID inSystemSoundID,id arg,NSDictionary* vibratePattern);
// Buzz code
NSArray *vibe = @[ @YES, @10 ]; // ON for 10ms
NSDictionary *dict = @{ @"Intensity": @0.1, @"VibePattern": vibe };
AudioServicesPlaySystemSoundWithVibration(kSystemSoundID_Vibrate,nil,dict);
@Air-Craft
Air-Craft / float_modulus_objc.m
Created April 7, 2015 15:54
Float modulus block #objective-c #math
CGFloat (^modulus)(CGFloat, CGFloat) = ^CGFloat(CGFloat dividend, CGFloat divisor) {
return dividend - floor(dividend / divisor) * divisor;
};
@Air-Craft
Air-Craft / indexpath_addition_math.m
Created April 7, 2015 10:01
Add/subtract from an IndexPath `item` property overflowing into `section` #objective-c #cocoa #index
- (NSIndexPath *)_indexPathByAdding:(NSInteger)N toIndexPath:(NSIndexPath *)idxPath
{
const NSInteger SIZE = 8;
NSInteger item = idxPath.item + N;
NSInteger sectionDelta = trunc(item / SIZE);
item = abs((int)item) % SIZE;
NSInteger section = idxPath.section + sectionDelta;
@Air-Craft
Air-Craft / objective_c_runtime_mixin.m
Created March 28, 2015 11:36
Mixin class method in Objective-C #objective-c #mixins #runtime #advanced
// MIXINS
+ (void)mixInto:(Class)destCls
{
NSAssert([[destCls alloc] isKindOfClass:[UIViewController class]], @"%@ is not a UIViewController subclass", destCls);
void (^inject)(Class, SEL, Class) = ^(Class srcCls,
SEL sel,
Class destcls){
Method newMethod = class_getInstanceMethod(srcCls, sel);
class_replaceMethod(destCls, sel, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)); // replace is like force-add, where addMethod fails if exists
@Air-Craft
Air-Craft / calayer_transform_w_perspective_anim.m
Created March 28, 2015 11:23
CALayer rotate, slide, fade in #animation with perspective #transform #3d
_alertContainer.alpha = 0.0;
CATransform3D t = CATransform3DIdentity;
t.m34 = -1.0 / 700;
t = CATransform3DRotate(t, -40*M_PI/180., 1.0, 0.0, 0);
t = CATransform3DTranslate(t, 0, -0, -200);
_alertContainer.layer.transform = t;
[UIView
animateWithDuration:self.animDuration
delay:0
@Air-Craft
Air-Craft / ios_app_version_string.m
Created March 19, 2015 08:09
Get app version strings #ios #strings #basic
return [NSString stringWithFormat:@"%@ v%@ (%@)",
[[NSBundle mainBundle] infoDictionary][@"CFBundleDisplayName"],
[[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"],
[[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"]];