Skip to content

Instantly share code, notes, and snippets.

View NSGod's full-sized avatar

Mark Douma NSGod

View GitHub Profile
@bladeSk
bladeSk / laravel-on-shared-hosting-htaccess.md
Last active June 12, 2024 14:40
Deploying Laravel on a shared hosting using only .htaccess

Deploying Laravel on a shared hosting using only .htaccess

Making Laravel work on a shared hosting can be troublesome, because Laravel needs to have its document root set to the public directory. This may not be configurable by a user or even desirable, when the server is hosting multiple websites.

Here's a simple method using only a .htaccess file placed in Laravel's root directory - e.g. alongside app, bootstrap, config, ... No changes whatsoever are necessary to your code.

The file rewrites all the requests so that requesting /file.png would in fact return /public/file.png and anything else is routed to /public/index.php. This also ensures that nothing outside the public folder can be accessed, thereby protecting any sensitive files like .env or database/*.

The simple method

@mminer
mminer / PreferencesViewController.swift
Last active May 19, 2024 05:06
NSTabViewController for preferences window that resizes itself to fit activated tab view.
import AppKit
class PreferencesViewController: NSTabViewController {
private lazy var tabViewSizes: [NSTabViewItem: NSSize] = [:]
override func tabView(_ tabView: NSTabView, didSelect tabViewItem: NSTabViewItem?) {
super.tabView(tabView, didSelect: tabViewItem)
if let tabViewItem = tabViewItem {
@dreikanter
dreikanter / encrypt_openssl.md
Last active October 25, 2024 08:57 — forked from crazybyte/encrypt_openssl.txt
File encryption using OpenSSL

Symmetic encryption

For symmetic encryption, you can use the following:

To encrypt:

openssl aes-256-cbc -salt -a -e -in plaintext.txt -out encrypted.txt

To decrypt:

@takuoka
takuoka / AutoGrowingTextField.swift
Last active January 18, 2022 13:02
Example of an NSTextField that expands its height automatically. https://github.com/DouglasHeriot/AutoGrowingNSTextField
import Cocoa
// https://github.com/DouglasHeriot/AutoGrowingNSTextField
// for AutoLayout
class AutoGrowingTextField: NSTextField {
var minHeight: CGFloat? = 100
@smileyborg
smileyborg / Xcode7Macros.h
Last active May 26, 2020 12:08
Backwards compatible macros for Objective-C nullability annotations and generics
/**
* The following preprocessor macros can be used to adopt the new nullability annotations and generics
* features available in Xcode 7, while maintaining backwards compatibility with earlier versions of
* Xcode that do not support these features.
*/
#if __has_feature(nullability)
# define __ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
# define __ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
# define __NULLABLE nullable
@boredzo
boredzo / PRHFrameGrabber+DraggingSource.m
Last active March 11, 2016 19:26
Dragging source code for promising files from my never-released movie player app.
//PRHFrameGrabber grabs frame images from the movie.
//It wraps a couple of AVAssetImageGenerators, one of which is allowed to round to a more convenient time (e.g., a keyframe).
//Thus, the temporally lax generator will return an image first, while we wait for the temporally strict generator, which may take a significant fraction of a second.
//PRHFrameGrabber is also an NSPasteboardWriter. It's what the movie view feeds to the dragging session when the user tries to drag a frame; the frame grabber fulfills its NSPasteboardWriter duties by returning the grabbed frame.
@interface PRHFrameGrabber ()
@property(readwrite, copy) NSImage *image;
@end
@implementation PRHFrameGrabber
@calebd
calebd / ArrayHelpers.swift
Last active November 4, 2022 15:17
Swift Helpers
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {
#!/bin/bash
# This script automatically sets the version and short version string of
# an Xcode project from the Git repository containing the project.
#
# To use this script in Xcode, add the script's path to a "Run Script" build
# phase for your application target.
set -o errexit
set -o nounset
@asmallteapot
asmallteapot / .gitattributes
Last active September 15, 2024 12:58
Diff Xcode localizable strings files in Git.
*.strings utf16 diff=localizablestrings
@sandymc
sandymc / CreateTransform.m
Last active September 3, 2020 23:25
This code snippet shows how to convert an image buffer between color spaces (e.g., transform from ProPhoto to sRGB or whatever) using Apple's new (and entirely undocumented) ColorSyncTransformConvert function. Firstly, a transform is created, then that transform is used to convert an image buffer.
const void *keys[] = {kColorSyncProfile, kColorSyncRenderingIntent, kColorSyncTransformTag};
const void *srcVals[] = {[srcProfile ref], kColorSyncRenderingIntentUseProfileHeader, kColorSyncTransformDeviceToPCS};
const void *dstVals[] = {[destProfile ref], kColorSyncRenderingIntentUseProfileHeader, kColorSyncTransformPCSToDevice};
CFDictionaryRef srcDict = CFDictionaryCreate (
NULL,
(const void **)keys,
(const void **)srcVals,
3,