Skip to content

Instantly share code, notes, and snippets.

@raecoo
raecoo / random-string.go
Created June 22, 2018 02:44
Random String - Go
// // https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang
func RandStringBytesMaskImprSrc(n int) string {
const (
letterBytes = "abcdefghijklmnopqrstuvwxyz0123456789"
letterIdxBits = 6 // 6 bits to represent a letter index
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
)
src := rand.NewSource(time.Now().UnixNano())
b := make([]byte, n)
@raecoo
raecoo / gist:9c85d647e2a45bd632751afb455c0e30
Created June 6, 2018 05:57 — forked from siddharthg/gist:6923b2cbb402bd65255af7859a5d52a5
Install Thrift 0.10.0 with brew on macOS
brew unlink thrift
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/16ebe5f1843e6cb54856311ff0f676be53007329/Formula/thrift.rb
@raecoo
raecoo / Map.scala
Created June 6, 2018 00:44
Scala Tips
Map("google"-> "search", "apple"-> "iPhone").map(_.productIterator.mkString(":")).mkString("|")
@raecoo
raecoo / apache-spark.rb
Last active May 26, 2018 09:29
Brew install Apache Spark 2.2.0
# override the file /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/apache-spark.rb as following content.
# Ref: https://stackoverflow.com/questions/49808951/how-to-install-apache-spark-2-2-0-with-homebrew-on-mac
class ApacheSpark < Formula
desc "Engine for large-scale data processing"
homepage "https://spark.apache.org/"
url "https://www.apache.org/dyn/closer.lua?path=spark/spark-2.2.0/spark-2.2.0-bin-hadoop2.7.tgz"
version "2.2.0"
sha256 "97fd2cc58e08975d9c4e4ffa8d7f8012c0ac2792bcd9945ce2a561cf937aebcc"
head "https://github.com/apache/spark.git"
@raecoo
raecoo / exception.log
Created April 23, 2018 08:51
shopify webhook 403 error
?> shop
=> #<Shop id: 2485, owner: "Aline Vanliefland", merchant: "The Tutu Shop", email: "[email protected]", shopify_domain: "tutu-shop.myshopify.com", shopify_token: "89107fa464660844e79e27883da335a3", domain: "www.tutu-shop.com">
pome(prod)> ShopifyAPI::Shop.current
=> #<ShopifyAPI::Shop:0x00555ccb8bb078 @attributes={"id"=>12848253, "name"=>"The Tutu Shop", "email"=>"[email protected]", "domain"=>"www.tutu-shop.com", "province"=>"", "country"=>"BE", "address1"=>"Lamorinièrestraat 123", "zip"=>"2018", "city"=>"ANTWERPEN", "source"=>nil, "phone"=>"+32479912555", "latitude"=>51.20397269999999, "longitude"=>4.420967, "primary_locale"=>"en", "address2"=>"", "created_at"=>"2016-05-09T11:46:54+02:00", "updated_at"=>"2018-04-04T11:56:30+02:00", "country_code"=>"BE", "country_name"=>"Belgium", "currency"=>"EUR", "customer_email"=>"[email protected]", "timezone"=>"(GMT+01:00) Brussels", "iana_timezone"=>"Europe/Brussels", "shop_owner"=>"Aline Vanliefland", "money_format"=>"€{{amount}}", "money_with_currency_for
@raecoo
raecoo / install-comodo-ssl-cert-for-nginx.rst
Created March 6, 2018 02:19 — forked from bradmontgomery/install-comodo-ssl-cert-for-nginx.rst
Steps to install a Comodo PositiveSSL certificate with Nginx.

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert

@raecoo
raecoo / middleware-test.go
Created January 15, 2018 13:47
golang middleware
package main
import (
"bytes"
"fmt"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
rendering "github.com/unrolled/render"
"io/ioutil"
"log"
package main
import (
"fmt"
"crypto/rand"
"math/big"
)
func Int64() (s int64, err error) {
bi := big.NewInt(9223372036854775807)
@raecoo
raecoo / 1.json
Created January 5, 2018 00:42
test heartbeat
{
"seq_num": 169,
"client_version": "1.0.0",
"target_data_list": [
{
"target_type": "c3.AVFoundation",
"item_list": [
{
"seq_num": 0,
"json_value": {
@raecoo
raecoo / authentication.lua
Created December 14, 2017 04:34
Lua + Authentication
function password_encode(password)
local bcrypt = require 'bcrypt'
return bcrypt.digest(password, 12)
end
function check_password(password, encoded_password)
local bcrypt = require 'bcrypt'
return bcrypt.verify(password, encoded_password)
end