Skip to content

Instantly share code, notes, and snippets.

@jmshal
jmshal / atob.js
Last active April 27, 2024 04:12
Node.js ponyfill for atob and btoa encoding functions
module.exports = function atob(a) {
return new Buffer(a, 'base64').toString('binary');
};
@shexbeer
shexbeer / gist:cb069d36ca8ec5edb515
Last active August 31, 2018 17:00
Crops a Picture from AVCaptureSession to the bounds of the AVCaptureVideoPreviewLayer (so Preview = CameraImage)
-(UIImage*) cropCameraImage:(UIImage*) original toPreviewLayerBounds:(AVCaptureVideoPreviewLayer*) previewLayer {
UIImage *ret = nil;
CGRect previewImageLayerBounds = previewLayer.bounds;
// This calculates the crop area.
// keeping in mind that this works with on an unrotated image (so a portrait image is actually rotated counterclockwise)
// thats why we use originalHeight to calculate the width
float originalWidth = original.size.width;
float originalHeight = original.size.height;