Skip to content

Instantly share code, notes, and snippets.

View lkrych's full-sized avatar

Leland Krych lkrych

  • Cisco
  • San Francisco, CA
View GitHub Profile
@lkrych
lkrych / fuzzy_search.rb
Last active April 5, 2018 21:44
Match substrings
# people is some subset from the Persons table
people = people.where("UPPER(first_name) LIKE UPPER(?) OR UPPER(last_name) LIKE UPPER(?)", "%" + params[:fname] + "%", "%" + params[:lname]+ "%")
@lkrych
lkrych / upper.rb
Created April 5, 2018 16:26
Demonstrating the use of the UPPER function in SQL
# people is some subset from the Persons table
people = people.where("UPPER(first_name) = UPPER(?) OR UPPER(last_name) = UPPER(?)", params[:fname], params[:lname])
@lkrych
lkrych / removeDups.go
Created March 20, 2018 15:10
more optimized remove dups
//In O(n) time, and using O(1) space, remove duplicates from an array
func removeDups(arr []int) []int {
nextUnduplicatedIdx := 1
//O(n) time complexity
for i := 1; i < len(arr); i++ {
//if the adjacent elements are not equal, assign the element at i to our nextUnduplicatedIdx
if arr[nextUnduplicatedIdx-1] != arr[i] {
arr[nextUnduplicatedIdx] = arr[i]
nextUnduplicatedIdx++
}
@lkrych
lkrych / removeDupsAlt.go
Created March 20, 2018 15:06
Un-optimized remove dups
func removeDupsAlt(arr []int) []int {
h := make(map[int]bool)
//O(n) time complexity
for i := 0; i < len(arr); i++ {
h[arr[i]] = true
}
//O(n) space complexity
keys := make([]int, len(h))
@lkrych
lkrych / scp.sh
Created February 25, 2018 04:54
scp
# will recursively transfer all the files in ./your_static_files
scp -i "your-key.pem" -r ./your_static_files ubuntu@ec2-<your-ip>compute-1.amazonaws.com:~/
@lkrych
lkrych / scp.sh
Created February 25, 2018 04:54
scp
# will recursively transfer all the files in ./your_static_files
scp -i "your-key.pem" -r ./your_static_files ubuntu@ec2-<your-ip>compute-1.amazonaws.com:~/
@lkrych
lkrych / ssh.sh
Created February 25, 2018 04:52
ssh
ssh -i "your-key.pem" ubuntu@ec2-<your-ip>.compute-1.amazonaws.com
@lkrych
lkrych / download_s3_files.go
Created February 16, 2018 16:57
download selected files from s3
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
@lkrych
lkrych / iterating_s3.go
Created February 16, 2018 16:39
search through s3 buckets
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
@lkrych
lkrych / search_params.go
Created February 16, 2018 15:53
use bucket and prefix to specify search path in s3
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"