Skip to content

Instantly share code, notes, and snippets.

View Golang filename without extension.go
package main
import (
"strings"
"path/filepath"
)
func fileNameWithoutExtension(fileName string) string {
return strings.TrimSuffix(fileName, filepath.Ext(fileName))
}
View Golang make directory if not exists.go
package main
import "os"
func makeDirectoryIfNotExists(path string) error {
if _, err := os.Stat(path); os.IsNotExist(err) {
return os.Mkdir(path, os.ModeDir|0755)
}
return nil
}
@ivanzoid
ivanzoid / gist:8353510
Last active Mar 24, 2021
Insert & delete rows in UITableView with animation
View gist:8353510
NSMutableArray *indexPathsToDelete = [NSMutableArray new];
for (Object *object in newObjects)
{
if (![currentObjects containsObject:object]) {
int row = [newObjects indexOfObject:object];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
[indexPathsToDelete addObject:indexPath];
}
}
View Linux find.sh
# A find Tutorial and Primer: https://danielmiessler.com/study/find/
find . -name '*.jpg'
# find only directories
find . -name 'foo' -type d
# find only files
find . -name 'foo' -type f
View Linux create tarball.sh
tar cvf file.tar path
tar cvzf file.tar.gz path
tar cvjf file.tar.bz2 path
View Golang write string to file.go
package main
import "os"
func writeStringToFile(path string, s string) error {
file, err := os.Create(path)
if err != nil {
return err
}
View Golang shabang.go
//usr/bin/env go run $0 -- "$@"; exit $?