Skip to content

Instantly share code, notes, and snippets.

@pmairoldi
pmairoldi / cursor.ts
Last active October 3, 2018 17:01
Cursor Movements
function moveCursorTo(node: Node, offset: number, native: Selection) {
// COMPAT: IE 11 does not support Selection.setBaseAndExtent, fallback to collapse
if (native.setBaseAndExtent) {
native.setBaseAndExtent(node, offset, node, offset);
} else {
native.collapse(node, offset);
}
}
#!/usr/bin/env ruby
class Configuration
attr_accessor :installer_path
attr_accessor :patch_path
attr_accessor :instance
attr_accessor :site
attr_accessor :directory
attr_accessor :database_server
attr_accessor :database_name
@pmairoldi
pmairoldi / MoyaFrameworkSpec.rb
Last active February 19, 2017 20:45
FrameworkSpec for Moya
language = swift("3.0")
platforms = [
macos("10.11"),
ios("8.0"),
tvos("9.0"),
watchos("2.0")
]
moya_tests = new_target do |target|
target.name = "MoyaTests"
require 'xcodeproj'
## PUBLIC INTERFACE ###
def project_name
'Moya'
end
def platforms
{
fastlane_version "1.34.0"
before_all do
keys
end
desc "Sets up private keys"
private_lane :keys do
require 'cocoapods-core'
puts "Validating CocoaPods Keys"
@pmairoldi
pmairoldi / Archiver.swift
Created October 9, 2015 15:53
Archiving swift objects
import Foundation
public protocol Archivable {
typealias T
static func decompress(object: AnyObject) -> T?
static func compress(object: T) -> AnyObject
}
import UIKit
import ReactiveCocoa
protocol Bindable {
func bind<T>(viewModel: T)
}
class TableViewBinding<T, E: ErrorType> {
//MARK: Properties
module Fastlane
module Actions
module SharedValues
DEVICES_LIST_CUSTOM_VALUE = :DEVICES_LIST_CUSTOM_VALUE
end
class ::String
def split_reject(pattern)
self.split(pattern).reject{|c|c.empty?}
end
- (NSString *)deviceIdentifier NS_AVAILABLE_IOS(8_0) {
UIScreen *screen = [UIScreen mainScreen];
CGSize size = screen.nativeBounds.size;
CGFloat scale = screen.nativeScale;
NSString *identifier = [NSString stringWithFormat:@"w_%.00f_h_%.00f", size.width / scale , size.height / scale];
return identifier;
@pmairoldi
pmairoldi / xcode-build-script
Last active September 6, 2015 03:13
Xcode build and version number (from tag)
#!/bin/bash
# This script automatically sets the version and short version string of
# an Xcode project from the Git repository containing the project.
#
# To use this script in Xcode, add the contents to a "Run Script" build
# phase for your application target.
# NOTE: make sure you add a new value to your Info plist called "FullVersion"
#