Skip to content

Instantly share code, notes, and snippets.

@ppamorim
ppamorim / ImageInsets.swift
Created November 5, 2015 16:30
Add padding/margin at a image!
import UIKit
extension UIImage {
func imageWithInsets(insetDimen: CGFloat) -> UIImage {
return imageWithInset(UIEdgeInsets(top: insetDimen, left: insetDimen, bottom: insetDimen, right: insetDimen))
}
func imageWithInset(insets: UIEdgeInsets) -> UIImage {
UIGraphicsBeginImageContextWithOptions(
CGSizeMake(self.size.width + insets.left + insets.right,
@jarrad
jarrad / install-kafka.txt
Last active August 24, 2023 08:23
Install Kafka on OSX via Homebrew
$> brew cask install java
$> brew install kafka
$> vim ~/bin/kafka
# ~/bin/kafka
#!/bin/bash
zkServer start
kafka-server-start.sh /usr/local/etc/kafka/server.properties
@mnbayan
mnbayan / MKMapViewExtension.swift
Created February 23, 2015 02:33
MKMapView extension to center map to coordinates with defined zoom level using Swift language
//
// MKMapViewExtension.swift
// AutocompleteTextfieldSwift
//
// Created by Mylene Bayan on 2/22/15.
// Copyright (c) 2015 MaiLin. All rights reserved.
//
import Foundation
import MapKit
@minorbug
minorbug / timeago.swift
Created November 7, 2014 15:28
"Time ago" function for Swift (based on MatthewYork's DateTools for Objective-C)
func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
let calendar = NSCalendar.currentCalendar()
let unitFlags = NSCalendarUnit.CalendarUnitMinute | NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitWeekOfYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitSecond
let now = NSDate()
let earliest = now.earlierDate(date)
let latest = (earliest == now) ? date : now
let components:NSDateComponents = calendar.components(unitFlags, fromDate: earliest, toDate: latest, options: nil)
if (components.year >= 2) {
return "\(components.year) years ago"
@Fire-
Fire- / requestUpload.js
Last active July 12, 2017 10:20
example for uploading files to Hipchat with the v2 api with node.js and the Request package
var request = require('request'), //ezmode
fs = require('fs');
var uploadFileName = 'tit.jpg'; // this is a local file, but could be any file or data you want to read in
//ITS A BIRD I SWEAR
fs.readFile('./' + uploadFileName, function read(err, data) {
// hipchat appears to expect the file as a byte array
// and does not support Content-Transfer-Encoding at the time of this gist's creation
request.post({
@stigi
stigi / CocoaLumberjack.swift
Created August 16, 2014 21:41
A little hack to work comfortably with cocoa lumberjack in Swift.
// Created by Ullrich Schäfer on 16/08/14.
// Bitmasks are a bit tricky in swift
// See http://natecook.com/blog/2014/07/swift-options-bitmask-generator/
//enum LogFlag: Int32 {
// case Error = 0b1
// case Warn = 0b10
// case Info = 0b100
@Inferis
Inferis / ViewController.swift
Last active December 1, 2019 23:27
Beginnings of a GCD wrapper in swift
import UIKit
import QuartzCore
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel
@IBOutlet weak var counter: UILabel
override func viewDidLoad() {
super.viewDidLoad()
@steveliles
steveliles / Foreground.java
Last active January 22, 2024 18:06
Class for detecting and eventing whether an Android app is currently foreground or background (requires API level 14+)
package com.sjl.util;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import java.util.List;
@kongchen
kongchen / setprop.sh
Last active January 3, 2023 09:29
set properties file value by key via bash shell
#!/bin/bash
############################
#script function
############################
setProperty(){
awk -v pat="^$1=" -v value="$1=$2" '{ if ($0 ~ pat) print value; else print $0; }' $3 > $3.tmp
mv $3.tmp $3
}
############################
@aras-p
aras-p / preprocessor_fun.h
Last active April 28, 2024 15:25
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,