Skip to content

Instantly share code, notes, and snippets.

View gregpardo's full-sized avatar

Greg P gregpardo

  • CTO @ PhotoDay
  • Florida
View GitHub Profile
@gregpardo
gregpardo / RxSwift+Realm.swift
Last active December 25, 2016 23:15
Simple extension on results object for swift realm
extension Realm {
public func rx_objectForPrimaryKey<T: Object>(type: T.Type, key: AnyObject) -> Observable<T?> {
return self.objects(type)
.filter("%K = %@", self.schema[type.className()]!.primaryKeyProperty!.name, key)
.rx_result
}
}
extension Results where T: Object {
@gregpardo
gregpardo / RxSwift+NVActivityIndicatorView.swift
Last active February 1, 2019 02:48
rx_animating extension for NVActivityIndicatorView
extension NVActivityIndicatorView {
public var rx_animating: AnyObserver<Bool> {
return UIBindingObserver(UIElement: self) { indicator, animating in
if (animating) {
indicator.startAnimation()
} else {
indicator.stopAnimation()
}
}.asObserver()
}
@gregpardo
gregpardo / UIImage+CropTransparent.swift
Last active July 19, 2019 12:58
Swift Image Crop Out Transparent Pixels (Swift 2.0)
extension UIImage {
func imageByCroppingTransparentPixels() -> UIImage {
let rect = self.cropRectForImage()
return cropImage(toRect: rect)
}
func cropRectForImage(image:UIImage) -> CGRect {
let imageAsCGImage = image.CGImage
let context:CGContextRef? = self.createARGBBitmapContext(imageAsCGImage!)
@arjan
arjan / controller.ex
Last active August 29, 2015 14:18
Twitter authorization controller
defmodule TestApp.TwitterController do
use Phoenix.Controller
# Routing configuration:
#
# scope "/twitter", TestApp do
# pipe_through :browser_session
# get "/:lang/authorize", TwitterController, :authorize
# get "/redirect", TwitterController, :authorize_return
@MarcDiethelm
MarcDiethelm / Contributing.md
Last active April 1, 2024 13:55
How to contribute to a project on Github

This text now lives at https://github.com/MarcDiethelm/contributing/blob/master/README.md. I turned it into a Github repo so you can, you know, contribute to it by making pull requests.


Contributing

If you want to contribute to a project and make it better, your help is very welcome. Contributing is also a great way to learn more about social coding on Github, new technologies and and their ecosystems and how to make constructive, helpful bug reports, feature requests and the noblest of all contributions: a good, clean pull request.

@strickyak
strickyak / gist:4201971
Created December 4, 2012 08:58
How to simulate classes and virtual methods in Golang.
/*
How to simulate classes and virtual methods in Go.
*/
package main
import . "fmt"
type A struct {
// Set My to outermost object (most derived class) after constructing.
@katanacrimson
katanacrimson / app.js
Created December 2, 2012 18:23
nodejs app - expressjs 3.0 + socket.io v9 + passport + redis
var express = require('express'),
passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
connect = require('connect'),
http = require('http'),
path = require('path'),
util = require('util'),
fs = require('fs'),
redis = require('redis'),
cookie = require('cookie'),
@jodell
jodell / nah_xcode_uncrustify.rb
Created February 20, 2012 04:34 — forked from mnem/nah_xcode_uncrustify.rb
Script file to be run as an Xcode 4 behaviour which uncrustifies the project source using reasonable Objective-C formatting defaults. Alternatively, you can run it and pass a path to uncrustify.
#!/usr/bin/env ruby
###########################################################################
# Script to be called as an Xcode 4 behaviour which will attempt to
# uncrustify all source files in the open project.
#
# (c) Copyright 2012 David Wagner.
#
# Complain/commend: http://noiseandheat.com/
#
#*************************************************************************#