Skip to content

Instantly share code, notes, and snippets.

View mario1in's full-sized avatar
:dependabot:
Focusing

Mario mario1in

:dependabot:
Focusing
View GitHub Profile
@mario1in
mario1in / git-change-commit-messages.md
Created May 17, 2019 08:02 — forked from nepsilon/git-change-commit-messages.md
How to change your commit messages in Git? — First published in fullweb.io issue #55

How to change your commit messages in Git?

At some point you’ll find yourself in a situation where you need edit a commit message. That commit might already be pushed or not, be the most recent or burried below 10 other commits, but fear not, git has your back 🙂.

Not pushed + most recent commit:

git commit --amend

This will open your $EDITOR and let you change the message. Continue with your usual git push origin master.

@mario1in
mario1in / fetchApps.m
Last active January 5, 2024 22:45
get installed apps on iOS11 / iOS 12
NSMethodSignature *methodSignature = [NSClassFromString(@"LSApplicationWorkspace") methodSignatureForSelector:NSSelectorFromString(@"defaultWorkspace")];
NSInvocation *invoke = [NSInvocation invocationWithMethodSignature:methodSignature];
[invoke setSelector:NSSelectorFromString(@"defaultWorkspace")];
[invoke setTarget:NSClassFromString(@"LSApplicationWorkspace")];
[invoke invoke];
NSObject * objc;
[invoke getReturnValue:&objc];
@mario1in
mario1in / DynamicInit.swift
Created November 29, 2018 11:11 — forked from Ben-G/DynamicInit.swift
Dynamically create instance based on type in Swift
protocol Initializable {
init()
}
class A : Initializable {
var content:String
required init() {
content = "TestContent"
}
@mario1in
mario1in / AddShadowAndRoundedCorners.swift
Created November 28, 2018 03:25 — forked from cwalo/AddShadowAndRoundedCorners.swift
Override layoutSubviews to add a new layer using a path with a roundedRect and cornerRadius
private var shadowLayer: CAShapeLayer!
private var cornerRadius: CGFloat = 25.0
private var fillColor: UIColor = .blue // the color applied to the shadowLayer, rather than the view's backgroundColor
override func layoutSubviews() {
super.layoutSubviews()
if shadowLayer == nil {
shadowLayer = CAShapeLayer()
@mario1in
mario1in / KeyboardMan.swift
Created April 27, 2018 08:15
支持 iOS 调用的 KeyboardMan
//
// KeyboardMan.swift
// Messages
//
// Created by NIX on 15/7/25.
// Copyright (c) 2015年 nixWork. All rights reserved.
//
import UIKit
@mario1in
mario1in / gist:a6e44b8da70bc07a8a707db445df065f
Created January 10, 2018 02:53 — forked from snikch/gist:3661188
Find the current top view controller for your iOS application
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
@mario1in
mario1in / image.m
Created February 10, 2017 08:22
图片居于顶部对齐显示
CGSize imageSize = image.size;
if (imageSize.height > imageSize.width) {
weakSelf.imageView.contentMode = UIViewContentModeScaleAspectFit;
weakSelf.imageView.image = image;
return;
}
CGFloat imageViewOriginX = 0;
CGFloat imageViewOriginY = 0;
@mario1in
mario1in / convertRect.m
Created February 8, 2017 02:19
将TableView上cell的frame转化为在VC.view中的frame
CGRect rect = [self.view convertRect:_button.frame fromView:_button.superview];
CGRect rect = [_button.superview convertRect:_button.frame toView:self.view];
@mario1in
mario1in / getMemory.m
Created January 4, 2017 06:27
获取iOS内存使用情况
#import <sys/sysctl.h>
#import <mach/mach.h>
- (double)availableMemory{
// 获取当前设备可用内存 (MB)
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount =HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(),
HOST_VM_INFO,
(host_info_t)&vmStats,
@mario1in
mario1in / disableLongPressGesturesForView.swift
Created January 4, 2017 06:22
禁用iOS9中部分系统长按webView出现的放大镜
func webViewDidFinishLoad(webView: UIWebView) {
disableLongPressGesturesForView(webView)
}
func disableLongPressGesturesForView(view: UIView) {
for subview in view.subviews {
if let gestures = subview.gestureRecognizers as [UIGestureRecognizer]! {
for gesture in gestures {
if gesture is UILongPressGestureRecognizer {
gesture.enabled = false