Skip to content

Instantly share code, notes, and snippets.

View zappycode's full-sized avatar

Zappy Code zappycode

View GitHub Profile
use anchor_lang::prelude::*;
// This is your program's public key and it will update
// automatically when you build the project.
declare_id!("ApNvFquHyG4kQTnAb3VAscw7URn3JDF6LYacsSzdxJqm");
#[program]
pub mod rgb_color_setter {
// Imports
use anchor_lang::solana_program::{
@zappycode
zappycode / NSImageToJpeg.swift
Last active December 31, 2023 03:40
Coverting an NSImage into JPEG Data
func jpegDataFrom(image:NSImage) -> Data {
let cgImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil)!
let bitmapRep = NSBitmapImageRep(cgImage: cgImage)
let jpegData = bitmapRep.representation(using: NSBitmapImageRep.FileType.jpeg, properties: [:])!
return jpegData
}
@zappycode
zappycode / Resize.swift
Created March 30, 2017 20:34
Resize NSImage
func resizeImage(image:NSImage, maxSize:NSSize) -> NSImage {
var ratio:Float = 0.0
let imageWidth = Float(image.size.width)
let imageHeight = Float(image.size.height)
let maxWidth = Float(maxSize.width)
let maxHeight = Float(maxSize.height)
// Get ratio (landscape or portrait)
if (imageWidth > imageHeight) {
// Landscape