Skip to content

Instantly share code, notes, and snippets.

@cvgw
cvgw / avl_tree.go
Created September 21, 2019 22:46
avl tree
package main
import (
"fmt"
"math"
"math/rand"
"strings"
)
type avlNode struct {
@cvgw
cvgw / linked_list_reverse.go
Last active March 22, 2019 00:18
Linked list playground
package main
import (
"fmt"
)
type linkedList struct {
value int
next *linkedList
}

Local file vulnerability

Summary

The C lib for 5.6 is compiled with support for local infiles by default. In order to disable the local infile behavior Consumers of the C lib must explicitly set the option MYSQL_OPT_LOCAL_INFILE to 0. The mysql2 gem only sets the MYSQL_OPT_LOCAL_INFILE option when the local_infile key is explicitly present in the Ruby client options. This means that 5.6 clients, which do not specify this key have the local infile behavior enabled making it the default for these clients.

@cvgw
cvgw / 00.kubebuilder.clean-new-controller
Last active January 3, 2019 01:47
Remove cruft from new controller.go created by kubebuilder
#!/bin/bash
set -e
controller_name=$1
file="${PWD}/pkg/controller/$controller_name/${controller_name}_controller.go"
COMMAND=$(cat <<'EOF'
controller_camel = ENV['CONTROLLER_NAME'].split('_').collect(&:capitalize).join
@cvgw
cvgw / main.go
Created December 12, 2018 05:55
Kubernetes UniversalDeserializer
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
log "github.com/sirupsen/logrus"
apps "k8s.io/api/apps/v1"
@cvgw
cvgw / main.go
Created December 12, 2018 05:50
Universal Deserializer Kubernetes + deployment and service selector validation
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
log "github.com/sirupsen/logrus"
apps "k8s.io/api/apps/v1"
@cvgw
cvgw / keybase.md
Created August 18, 2017 22:10
Keybase.io verification

Keybase proof

I hereby claim:

  • I am cvgw on github.
  • I am cvgw (https://keybase.io/cvgw) on keybase.
  • I have a public key whose fingerprint is 48CE 6F08 577C 3762 2A70 5F3A 5C5A 67AE 0B17 3668

To claim this, I am signing this object:

@cvgw
cvgw / db_model_generator.rb
Created December 5, 2015 18:32
Rails Custom Generator for DB Model
class DbModelGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
hook_for :test_framework, in: :rspec, as: :model do |instance, invoke|
instance.invoke "controller", [instance.name.pluralize]
instance.invoke "model"
end
def create_files
# create custom files here, be sure to add them to your
@cvgw
cvgw / resource_generator.rb
Created December 4, 2015 07:33
Call multiple Rspec generators in a custom Rails generator
class ResourceGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
def create_files
template "action.rb", "app/actions/#{file_name}_actions.rb"
template "action_spec.rb", "spec/actions/#{file_name}_actions_spec.rb"
end
hook_for :test_framework, in: :rspec, as: :model do |instance, invoke|
instance.invoke "controller", [instance.name.pluralize]
@cvgw
cvgw / Intercom Implementation
Created April 28, 2015 19:43
Here is out implementation of the intercom in app messenger using our custom loader instead of inline JS. Current_user is just a backbone model, which is retrieved by the getMe() method.
this.app.load('intercom', function (root, app) {
'use strict';
var current_user;
var startIntercom = function () {
window.intercomSettings = {
// TODO: The current logged in user's full name
name: current_user.attributes.name,