Skip to content

Instantly share code, notes, and snippets.

@cristianca
cristianca / profile_middleware.py
Last active May 30, 2017 08:35
Profile Middleware
import logging
try:
import cProfile as profile
except ImportError:
import profile
import pstats
@cristianca
cristianca / Create color with gradient
Last active April 14, 2023 18:25
Create a gradient UIColor from an array of colors.
func colorWithGradient(frame: CGRect, colors: [UIColor]) -> UIColor {
// create the background layer that will hold the gradient
let backgroundGradientLayer = CAGradientLayer()
backgroundGradientLayer.frame = frame
// we create an array of CG colors from out UIColor array
let cgColors = colors.map({$0.CGColor})
backgroundGradientLayer.colors = cgColors
// insert text at cursor position in a Google Docs using apps script.
function insertTextAtCursorPosition(text) {
var doc = DocumentApp.getActiveDocument();
var cursor = doc.getCursor();
if (cursor) {
text = cursor.insertText(text);
position = doc.newPosition(text, text.getText().length);
doc.setCursor(position);
}
}