Skip to content

Instantly share code, notes, and snippets.

@karltaylor
karltaylor / UIBorderedLabel.swift
Created December 1, 2016 14:46 — forked from karloscarweber/UIBorderedLabel.swift
UILabel subclass that makes setting padding really easy.
View UIBorderedLabel.swift
//
// UIBorderedLabel.swift
// standToMake
//
// Created by Karl Oscar Weber on 9/13/14.
// Copyright (c) 2014 Karl Oscar Weber. All rights reserved.
//
// Thanks to: http://userflex.wordpress.com/2012/04/05/uilabel-custom-insets/
import UIKit
@karltaylor
karltaylor / convertImg.sh
Created August 12, 2016 16:52
Convert image to different format.
View convertImg.sh
for i in *.png; do convert -verbose $i ${i%%.png}.jpg; done && open .
@karltaylor
karltaylor / resizeImg.sh
Created August 9, 2016 11:42
Bash script to resize multiple images at once.
View resizeImg.sh
for i in *.jpg; do convert $i -resize 1472x983 $i; done
@karltaylor
karltaylor / compress-images.sh
Last active July 3, 2017 10:40
Compress image
View compress-images.sh
convert -strip -interlace Plane -sampling-factor 4:2:0 -quality 85% part-1.jpg result.jpg
@karltaylor
karltaylor / split.js
Last active July 7, 2017 11:28
Split string but keep delimiter
View split.js
function split(string) {
return string.match(/\w+(?:\s\w+)*\W?/g)
}
console.log(split("string one, string two, thing three, four four."))
// ["string one,", "string two,", "thing three,", "four four."]
// https://regex101.com/r/1mn4J9/1/
@karltaylor
karltaylor / ffmpeg-resize-convert-compress-all.sh
Last active June 19, 2018 20:26
Bash script to scale, convert and compress videos within a directory to .webm
View ffmpeg-resize-convert-compress-all.sh
for file in *.mp4; do ffmpeg -i "$file" -filter:v scale=1080:-1 -acodec libvorbis -ac 2 -b:v 5000k "${file%.mp4}".webm; done
@karltaylor
karltaylor / main.code-snippets
Created June 21, 2018 10:57
Visual Studio Code Snippets
View main.code-snippets
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
@karltaylor
karltaylor / handle-input-change.js
Last active August 2, 2018 15:33
Handle Input Change React
View handle-input-change.js
handleChange = e => {
const {name, value} = e.currentTarget
this.setState({
[name]: value
})
}
// Make sure you've set a 'name' attribute on the input.
View EditUserProfile.js
// @flow
import React, { useState } from 'react';
import { KeyboardAvoidingView, ScrollView, Text, View } from 'react-native';
import { Header } from '../../components/Header';
import { Button } from '../../components/Button';
import { ProfileImage } from '../../components/ProfileImage';
import PostInput from '../../components/PostInput';
import PostBody from '../../components/PostBody';
@karltaylor
karltaylor / findAndReplace.js
Last active March 24, 2020 11:31
Module to find and replace parts of a file.
View findAndReplace.js
const fs = require('fs');
const signale = require('signale');
module.exports = (filePath, regex, replacement) =>
new Promise((yep, nope) => {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.log(err); // eslint-disable-line
nope(err);
}