Skip to content

Instantly share code, notes, and snippets.

View karlmutch's full-sized avatar
🇳🇿
( ಠ ͜ʖಠ)

Karl Mutch karlmutch

🇳🇿
( ಠ ͜ʖಠ)
View GitHub Profile
36 wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u40-b26/jdk-8u40-linux-x64.tar.gz
37 javac
38 tar xvfo jdk-8u40-linux-x64.tar.gz
39 chown -R root: jdk1.8.0_40
40 sudo alternatives --install /usr/bin/java java /opt/jdk1.8.0_40/bin/java 1
41 sudo alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_40/bin/javac 1
42 sudo alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_40/bin/jar 1
43 ls
44 rm jdk
45 rm jdk-8u40-linux-x64.tar.gz
@karlmutch
karlmutch / gist:221e705051bb56e4cad0
Created May 2, 2015 19:03
This problem comes from a Google+ group and was described as * * You have an array of integers, and for each index you want to find the product of every integer except * the integer at that index. Write a function get_products_of_all_ints_except_at_index() that takes an * array of integers and returns an array of the products.
public static BigInteger [] get_products_of_all_ints_except_at_index(BigInteger [] input)
{
ArrayList<BigInteger> productResults = new ArrayList<BigInteger>(input.length);
BigInteger masterProduct = BigInteger.ONE;
for (BigInteger anItem : input) {
masterProduct = masterProduct.multiply(anItem);
}
for (BigInteger anItem : input) {
Using Java, with no help from 3rd party libraries, there is the old way and the new way. Just sorting used to be easy with Collections.sort(..).
The challenge with the old way was that a lot of code was required to group the values.
- Input: List<String>
- Output: Map<Character,<List<String>>
- The key of map is 'A' to 'Z'
- Each list in the map are sorted.
Old Java
func init() {
http.HandleFunc("/", errorHandler(betterHandler))
}
func errorHandler(f func(http.ResponseWriter, *http.Request) error) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
err := f(w, r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Printf("handling %q: %v", r.RequestURI, err)
var (
Web = fakeSearch("web")
Image = fakeSearch("image")
Video = fakeSearch("video")
)
type Search func(query string) Result
func fakeSearch(kind string) Search {
return func(query string) Result {
func WordCount(s string) map[string]int {
wcMap := make(map[string]int)
for _,word := range strings.Fields(s) {
if _,ok := wcMap[word] ; ok {
wcMap[word]++
} else {
wcMap[word] = 1
}
}
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
accum1 := 1
accum2 := 0
return func() int {
// string and rune
const sample = "\xbd\xb2\x3d\xbc\x20\xe2\x8c\x98"
fmt.Printf("%x\n", sample) "bdb23dbc20e28c98"
fmt.Printf("% x\n", sample) "bd b2 3d bc 20 e2 8c 98"
fmt.Printf("%q\n", sample) "\xbd\xb2=\xbc ⌘"
fmt.Printf("%+q\n", sample) "\xbd\xb2=\xbc \u2318"
const nihongo = "日本語"

Keybase proof

I hereby claim:

  • I am karlmutch on github.
  • I am karlmutch (https://keybase.io/karlmutch) on keybase.
  • I have a public key ASBi1fSM4ozPiy_0S-Cus0CNsEIiKaS4pNfKLBgWgvVf4Ao

To claim this, I am signing this object:

@karlmutch
karlmutch / postgres_array.go
Created April 12, 2017 21:35 — forked from adharris/postgres_array.go
PostgreSQL demo of Array types using Golang
package main
import (
"database/sql"
"errors"
"fmt"
_ "github.com/bmizerany/pq"
"os"
"regexp"
"strings"