Skip to content

Instantly share code, notes, and snippets.

@zummenix
zummenix / RotationDifference.m
Created May 15, 2018 09:05
Finds rotation difference between two interface orientations
/**
Finds rotation difference between two interface orientations.
For example, difference between Portrait and PortraitUpsideDown is 2 (rotate by 180 degrees),
defference between Portrait and LandscapeLeft is 1 (rotate by 90 degrees).
@param source source interface orientation
@param destination destination interface orientation
@return rotation difference between orientations in range [0, 3].
*/
NSInteger rotationDifference(UIInterfaceOrientation source, UIInterfaceOrientation destination) {
@zummenix
zummenix / zsh-prompt-snippet.sh
Last active February 11, 2018 18:15
A snippet for zsh prompt.
local path_string="%~"
local git_string='$(git_prompt_info)'
local prompt_string="λ"
local return_status="%(?:%{$fg[green]%}$prompt_string:%{$fg[red]%}$prompt_string)"
PROMPT="${return_status} %{$reset_color%}"
RPROMPT="%{$fg[yellow]%}${git_string}%{$reset_color%} ${path_string}"
fswatch -0 -e ".*" -i "\\.swift$" . | xargs -0 -n 1 -I {} swiftformat {}
@zummenix
zummenix / resize.py
Last active November 3, 2017 11:19
A script to resize an app icon for all sizes required by xcode
#!/usr/bin/env python
from subprocess import call
import os
def format_name(size, scale):
return str(size) + "@" + str(scale) + "x"
def resize(size, scale):
name = format_name(size, scale)
@zummenix
zummenix / scroll.swift
Created April 6, 2017 06:27
Scroll to bottom for table views with dynamic sized cells
/// Scrolls to the bottom of the table view, typically used to skip content.
///
/// For precise scrolling please use `scrollToBottom(animated:)`.
fileprivate func initialScrollToBottom() {
if tableView.contentSize.height >= tableView.bounds.size.height {
tableView.contentOffset.y = tableView.contentSize.height - tableView.bounds.size.height
}
}
/// Scrolls to the bottom of the table view.
@zummenix
zummenix / UIImage+RadialGradient.swift
Created August 8, 2016 07:22
Generates an image with radial gradient.
private extension UIImage {
static func radialGradientImageWithSize(size: CGSize, outerColor: UIColor, innerColor: UIColor) -> UIImage {
let colorSpace = CGColorSpaceCreateDeviceRGB()
let gradient = CGGradientCreateWithColors(colorSpace, [outerColor.CGColor, innerColor.CGColor], [1.0, 0.0])
let center = CGPoint(x: size.width / 2.0, y: size.height / 2.0)
UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.mainScreen().scale)
let imageContext = UIGraphicsGetCurrentContext()
CGContextDrawRadialGradient(imageContext, gradient, center, 0.0, center, size.width / 2.0, CGGradientDrawingOptions.DrawsAfterEndLocation)
@zummenix
zummenix / UIColor+Brightness.swift
Created August 8, 2016 07:21
Allows to change brightness of an UIColor.
private extension UIColor {
func addedBrightness(value: CGFloat) -> UIColor {
var cs: (hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) = (0.0, 0.0, 0.0, 0.0)
self.getHue(&cs.hue, saturation: &cs.saturation, brightness: &cs.brightness, alpha: &cs.alpha)
return UIColor(hue: cs.hue, saturation: cs.saturation, brightness: cs.brightness + value, alpha: cs.alpha)
}
}
@zummenix
zummenix / Main.elm
Created July 23, 2016 07:08
Main.elm template
import Html.App
import Html exposing (div, Html)
main : Program Never
main = Html.App.program { init = init, view = view, update = update, subscriptions = subscriptions }
type alias Model = Int
type Msg = None
@zummenix
zummenix / Ascetic.tmTheme
Created June 13, 2016 13:31
Minimalistic light color theme for vscode.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Ascetic</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
FROM jimmycuadra/rust
MAINTAINER Aleksey Kuznetsov, zummenix@gmail.com
ENV CARGO_HOME /cargo
RUN mkdir -p "$CARGO_HOME"
CMD ["/bin/bash"]