Skip to content

Instantly share code, notes, and snippets.

@kseada
kseada / Mac SSH and SCP Autocomplete
Last active August 15, 2018 18:52 — forked from aliang/Mac SSH Autocomplete
Add auto complete to your ssh, put into your .bash_profile
_complete_ssh_hosts ()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
grep -v ^# | \
uniq | \
grep -v "\[" ;
@kseada
kseada / QuickSort.scala
Last active November 1, 2016 16:25
Quick Sort in Scala.
def quickSortRecursive(list: Array[Int])(low: Int=0, high: Int=list.length-1): Unit = {
if (low<high) {
swap(list,Random.nextInt(high),high)
val pivot = partition(list, low, high)
quickSortRecursive(list)(low, pivot-1)
quickSortRecursive(list)(pivot+1, high)
}
}
private def partition(list: Array[Int], low: Int, high: Int): Int = {
@kseada
kseada / BinarySearch.scala
Last active November 1, 2016 16:26
Showing alternative ways for implementing binary search in Scala: iterative, recursive and functional pattern matching.
def binarySearchIterative(list: Array[Int], target: Int): Int = {
var left = 0
var right = list.length-1
while (left<=right) {
val mid = left + (right-left)/2
if (list(mid)==target)
return mid
else if (list(mid)>target)
right = mid-1
else
@kseada
kseada / GSAccess.scala
Created February 21, 2013 19:13
Scala code for accessing Google Storage using JetS3t. Add repository to sbt resolvers: "jets3t" at "http://www.jets3t.org/maven2", and library to sbt libraryDependencies: , "net.java.dev.jets3t" % "jets3t" % "0.9.0".
import org.jets3t.service.security.GSCredentials
import org.jets3t.service.impl.rest.httpclient.GoogleStorageService
import org.jets3t.service.model.GSObject
import org.jets3t.service.ServiceException
import java.io.File
import java.io.BufferedReader
import java.io.InputStreamReader
val BUCKET_NAME = "###"
val FILE_PATH = "###"
@kseada
kseada / S3Access.scala
Last active June 1, 2022 09:15
Scala code for accessing Amazon S3 using AWS SDK for Java. Add dependency to sbt libraryDependencies: "com.amazonaws" % "aws-java-sdk" % "1.3.32"
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.AmazonClientException
import com.amazonaws.AmazonServiceException
import java.io.File
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.FileOutputStream
import org.apache.commons.io.IOUtils