Skip to content

Instantly share code, notes, and snippets.

View jarifibrahim's full-sized avatar
🎯
Focusing

Ibrahim Jarif jarifibrahim

🎯
Focusing
View GitHub Profile
package table
import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"testing"
"time"
@jarifibrahim
jarifibrahim / benchmarkinterface.go
Created September 18, 2019 13:29
Benchmark interface
type foo interface {
increment()
}
type X struct {
i int
}
func (x *X) increment() {
x.i++
package main
import (
"fmt"
"log"
"github.com/dgraph-io/badger"
)
func main() {
@jarifibrahim
jarifibrahim / makefile
Created March 20, 2019 12:04
devopsconsole-operator makefile
PROJECT_NAME=devopsconsole-operator
PACKAGE_NAME:=github.com/redhat-developer/$(PROJECT_NAME)
CUR_DIR=$(shell pwd)
TMP_PATH=$(CUR_DIR)/tmp
INSTALL_PREFIX=$(CUR_DIR)/bin
VENDOR_DIR=vendor
INCLUDE_DIR=make
SOURCE_DIR ?= .
SOURCES := $(shell find $(SOURCE_DIR) -path $(SOURCE_DIR)/vendor -prune -o -name '*.go' -print)
@jarifibrahim
jarifibrahim / jenkins.txt
Created February 1, 2019 11:33
Jenkins log
OPENSHIFT_JENKINS_JVM_ARCH is set to i686 so using 32 bit Java
Feb 01, 2019 11:27:42 AM INFO: Using temp directory /var/lib/jenkins/tmp.3QqiSqnR0i for generating configurations
Feb 01, 2019 11:27:53 AM INFO: Generating kubernetes-plugin configuration (/opt/openshift/configuration/config.xml.tpl)
Feb 01, 2019 11:27:53 AM INFO: Generating kubernetes-plugin credentials (credentials.xml) ...
Feb 01, 2019 11:27:53 AM INFO: Copying Jenkins configuration to /var/lib/jenkins
Feb 01, 2019 11:27:53 AM INFO: Removing template files (*.tpl) from /var/lib/jenkins
Feb 01, 2019 11:27:53 AM INFO: Removed temp directory /var/lib/jenkins/tmp.3QqiSqnR0i
Removing existing /var/lib/jenkins/plugins from gluster storage
Symlinking /var/lib/jenkins/plugins to /opt/openshift/plugins
@jarifibrahim
jarifibrahim / cleaner.go
Last active February 9, 2024 16:37
Database cleanup hook using GORM
// DeleteCreatedEntities sets up GORM `onCreate` hook and return a function that can be deferred to
// remove all the entities created after the hook was set up
// You can use it as
//
// func TestSomething(t *testing.T){
// db, _ := gorm.Open(...)
//
// cleaner := DeleteCreatedEntities(db)
// defer cleaner()
//
@jarifibrahim
jarifibrahim / cleanup_test.go
Last active October 17, 2023 19:01
Cleaning up test fixtures with GORM hooks
package main
import (
"database/sql"
"fmt"
"testing"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
@jarifibrahim
jarifibrahim / cleanup_test.go
Last active January 27, 2019 08:39
Gist showing a not-so-cool way of deleting test fixtures
package main
import (
"database/sql"
"testing"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
@jarifibrahim
jarifibrahim / main.go
Created January 27, 2019 07:26
GORM - Insert, Update and Delete operation
package main
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
type Product struct {
gorm.Model
Code string
@jarifibrahim
jarifibrahim / oc-new-app-all.sh
Last active January 26, 2019 13:59
oc new app command to build golang-health-check image/resources
➜ ~ oc new-app -f https://raw.githubusercontent.com/golang-starters/golang-health-check/master/.openshiftio/application.yaml \
-p SOURCE_REPOSITORY_URL=https://github.com/golang-starters/golang-health-check
--> Deploying template "ijarif-preview-stage/launchpad-builder" for "https://raw.githubusercontent.com/golang-starters/golang-health-check/master/.openshiftio/application.yaml" to project ijarif-preview-stage
launchpad-builder
---------
This template creates a Build Configuration using an S2I builder.
* With parameters:
* Suffix name=