Skip to content

Instantly share code, notes, and snippets.

@dnwe
dnwe / example_test.go
Last active September 18, 2023 22:02
Ruleguard
package example
import "testing"
func TestXYZ(t *testing.T) {
tests := []struct {
name string
want int
}{
{
@dnwe
dnwe / .semgrep.yml
Created November 30, 2020 12:34
Java semgrep for String#replaceAll("...", "...")
rules:
- id: java.lang.string.replaceall-is-slow
message: |
Look out for invocations of regexp mehods like String#replaceAll("...", "...") on hot code paths.
Compiling into a reusable Pattern instance is almost always the preferable option.
severity: WARNING
patterns:
- pattern-either:
- pattern: |-
$STRING.replaceAll("...", "...")
diff --git a/ruleguard.rules.go b/ruleguard.rules.go
index 5d4c4fe..8d2f8c1 100644
--- a/ruleguard.rules.go
+++ b/ruleguard.rules.go
@@ -130,6 +130,34 @@ func errnoterror(m fluent.Matcher) {
Report("err variable not error type")
}
+// err found but return nil
+func errfoundreturnnil(m fluent.Matcher) {
@dnwe
dnwe / github_enforcer.go
Created March 4, 2020 15:50
Enforces the correct team-ownership, protected branches, status checks etc. permissions across an org/user
package main
import (
"context"
"fmt"
"log"
"net/http"
"net/url"
"os"
"reflect"
@dnwe
dnwe / consumer-group-commit.go
Created February 19, 2020 16:23
Sarama example to subscribe to a topic and immediately commit the current end offset for the assigned partitions.
package main
import (
"context"
"fmt"
"log"
"os"
"sync"
"github.com/Shopify/sarama"
@dnwe
dnwe / disable_commit_agents_docker_container.groovy
Created March 19, 2018 14:06
Jenkins groovy script to remove the "Commit agent's Docker container" setting from all projects
import com.cloudbees.plugins.flow.*;
import com.nirima.jenkins.plugins.docker.DockerJobProperty;
projects = Jenkins.instance.getAllItems();
projects.each { project ->
removed = false
project.properties.find{ it.key instanceof com.nirima.jenkins.plugins.docker.DockerJobProperty.DescriptorImpl }.each { property ->
project.removeProperty(property.value)
removed = true
}
@dnwe
dnwe / count_pdf_pages.py
Created January 8, 2017 10:42
Pure Python script to count the number of pages in a directory of PDF files
#!/usr/bin/env python2
import os
import sys
import re
import fnmatch
import logging
logging.basicConfig(
stream=sys.stdout,
#!/usr/bin/env python
import os
import sys
import fnmatch
import logging
import zipfile
logging.basicConfig(
stream=sys.stdout,
@dnwe
dnwe / kafka_roundtrip.py
Created August 11, 2016 13:57
Simple proof of concept for using kafka-python to talk to IBM Message Hub
#!/usr/bin/python3
"""
Simple proof of concept for using kafka-python to talk to IBM Message Hub
https://gist.github.com/dnwe
http://kafka-python.readthedocs.io/
"""
import os
import ssl
// A template build.gradle to invoke the jobdsl plugin on the .groovy files
// which will syntactically validate them and output the generated Jenkins XML
// into the build directory.
repositories {
mavenCentral()
maven { url 'http://repo.jenkins-ci.org/releases/' }
}
dependencies {
compile 'org.jenkins-ci.plugins:job-dsl-core:1.46'