Skip to content

Instantly share code, notes, and snippets.

var randomNumbers = [42, 12, 88, 62, 63, 56, 1, 77, 88, 97, 97, 20, 45, 91, 62, 2, 15, 31, 59, 5]
func partition(v: Int[], left: Int, right: Int) -> Int {
var i = left
for j in (left + 1)..(right + 1) {
if v[j] < v[left] {
i += 1
(v[i], v[j]) = (v[j], v[i])
}
}
@calebd
calebd / ArrayHelpers.swift
Last active January 29, 2025 06:05
Swift Helpers
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {
@jhaberstro
jhaberstro / monoid.swift
Last active December 14, 2015 18:39
Swift monoid, num, Sum typeclasses with Int32 instances
protocol Monoid {
class func mzero() -> Self
func mop(y: Self) -> Self
}
func mconcat<M : Monoid>(t: Array<M>) -> M {
return (t.reduce(M.mzero()) { $0.mop($1) })
}
protocol Num {
@marklarr
marklarr / swiftRegex.swift
Created June 3, 2014 06:53
Ruby-esque regex in Swift
// Regex
import Foundation
operator infix =~ {}
@infix func =~ (str: String, pattern: String) -> Bool {
var error: NSError?
let regex = NSRegularExpression.regularExpressionWithPattern(pattern, options: nil, error: &error)
if (error) { return false }
@lyoshenka
lyoshenka / ngrok-selfhosting-setup.md
Last active February 21, 2025 08:33
How to setup Ngrok with a self-signed SSL cert

Intro

The plan is to create a pair of executables (ngrok and ngrokd) that are connected with a self-signed SSL cert. Since the client and server executables are paired, you won't be able to use any other ngrok to connect to this ngrokd, and vice versa.

DNS

Add two DNS records: one for the base domain and one for the wildcard domain. For example, if your base domain is domain.com, you'll need a record for that and for *.domain.com.

Different Operating Systems

@paul91
paul91 / GraphicsMagick.sh
Last active September 20, 2020 17:02
How to install GraphicsMagick on CentOS 6.4
#!/bin/bash
# Install build dependencies
yum install -y gcc libpng libjpeg libpng-devel libjpeg-devel ghostscript libtiff libtiff-devel freetype freetype-devel
# Get GraphicsMagick source
wget ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/1.3/GraphicsMagick-1.3.9.tar.gz
tar zxvf GraphicsMagick-1.3.9.tar.gz
# Configure and compile
@tboggs
tboggs / dirichlet_plots.png
Last active July 10, 2024 13:49
A script to generate contour plots of Dirichlet distributions
dirichlet_plots.png
@cgkio
cgkio / install_git_raspberry_pi.sh
Created December 25, 2013 21:47
Raspberry Pi setup crib sheet (private)
sudo apt-get update
# node.js
wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb
node -v
# git
sudo apt-get install git
# heimcontrol.js
sudo apt-get install git-core git scons build-essential scons libpcre++-dev xulrunner-dev libboost-dev libboost-program-options-dev libboost-thread-dev libboost-filesystem-dev
git clone git://github.com/RickP/mongopi.git
@sag333ar
sag333ar / getIPAddress.m
Last active June 23, 2017 14:12
Put this method into your class & you can obtain the IP address of current device.
// get the IP address of current-device
- (NSString *)getIPAddress {
NSString *address = @"error";
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
// retrieve the current interfaces - returns 0 on success
success = getifaddrs(&interfaces);
if (success == 0) {
// Loop through linked list of interfaces
@mbigatti
mbigatti / UIView+BMXMotionEffect
Created October 17, 2013 08:17
Add device tilting support to your UIView to get an effect similar to native UIAlertView
#import <UIKit/UIKit.h>
@interface UIView (BMXMotionEffect)
- (void)BMX_addTwoDimensionMotionEffectWithDepth:(CGFloat)depth;
@end
#import "UIView+BMXMotionEffect.h"