Skip to content

Instantly share code, notes, and snippets.

View liufsd's full-sized avatar
🎯
Focusing

liupeng liufsd

🎯
Focusing
View GitHub Profile
@burczyk
burczyk / quicksort.swift
Created January 2, 2015 11:51
Quicksort the Swift way
var list = [8,1,55,34,13,8,5,0,1,3,2,21]
func quicksort1(list:[Int]) -> [Int] {
if list.count == 0 {
return []
}
let pivotValue = list[0]
let smaller = filter(list, { $0 < pivotValue })
smaller
@stuartjmoore
stuartjmoore / WPTextAttachment.h
Last active October 21, 2016 13:08
Creates an NSTextAttachment the takes up the entire width of the line fragment (while maintaining its aspect ratio). Instead of a simple image, any UIView (that has a (CGFloat)heightThatFits method) will work.
//
// WPTextAttachment.h
// ReadArticle
//
// Created by Moore, Stuart on 12/27/13.
// Copyright (c) 2013 The Washington Post. All rights reserved.
//
#import <UIKit/UIKit.h>
@suya55
suya55 / ij.sh
Last active June 21, 2017 14:28
Open a project in IntelliJ IDEA from your command line! Raw
#!/bin/sh
# check for where the latest version of IDEA is installed
IDEA=`ls -1d /Applications/IntelliJ\ * | tail -n1`
wd=`pwd`
# Setup your working directory. Edit 'work' to your working directory.
working_dir=`ls -1d ~/work/$1 | head -n1`
# were we given a directory?
if [ -d "$1" ]; then
@codebutler
codebutler / BetterContentProvider.java
Created May 15, 2012 20:41
The missing ContentProvider base class.
import android.content.*;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.provider.BaseColumns;
import android.text.TextUtils;
public abstract class BetterContentProvider extends ContentProvider {
@Daij-Djan
Daij-Djan / ArrayUtils.swift
Last active February 2, 2018 20:49
Added an Array extension with contains & indexOf -- bridging to NSArray is ugly and that hides it
import Foundation
extension Array {
func contains<U: Equatable>(object:U) -> Bool {
return (self.indexOf(object) != nil);
}
func indexOf<U: Equatable>(object: U) -> Int? {
for (idx, objectToCompare) in self.enumerate() {
if let to = objectToCompare as? U {
@ningsuhen
ningsuhen / Regex.swift
Last active April 27, 2019 18:39
Swift extension for Native String class to support Regex match and Regex replace. Credit - http://www.swift-studies.com/blog/2014/6/12/regex-matching-and-template-replacement-operators-in-swift
import Foundation
struct Regex {
var pattern: String {
didSet {
updateRegex()
}
}
var expressionOptions: NSRegularExpressionOptions {
didSet {
@coolaj86
coolaj86 / node-sqlcipher.md
Last active May 1, 2019 20:24
Encrypted Full-Text Search with SQLite (SQLCipher) in Node.js
# code based on https://en.wikipedia.org/wiki/Mahalanobis_distance
set.seed(1)
# define a point D
x <- matrix(rmnorm(1, c(2,2), matrix(c(1,0.1,0.1,1), 2, 2)), 1, 2) # vector of locations in 2 dimensional space
x <- t(x) # transpose
# Define a multivariate normal distribution for comparison
mu <- matrix(c(0, 0), 1, 2) # vector of bivariate means
//
// ContentView.swift
// SwiftUI Chat
//
// Created by Nick Halavins on 6/7/19. Updated 10/11/19
// Copyright © 2019 AntiLand. All rights reserved.
//
import SwiftUI
@Kapeli
Kapeli / NSCrapField.m
Last active March 9, 2020 18:57
Yosemite NSSearchField Fixes
// 1. Disable centered look & animation:
// 1.1. Subclass NSSearchFieldCell and add:
- (BOOL)isCenteredLook
{
return NO;
}
// 1.2. Subclass NSSearchField and add: