Skip to content

Instantly share code, notes, and snippets.

@rtrouton
rtrouton / gist:7238371
Last active September 3, 2024 15:36
Script to handle unbinding your Mac from one OpenLDAP server and moving to another. Also handles AD domains differently. If you are adapting this for your own use, run a search and replace for the following: "dc=replaceme,dc=org" (no quotes) You'll need to replace that with your own LDAP search base "ldap.server.goes.here" (no quotes) You'll nee…
#!/bin/sh
# Determine OS version
osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
# Environment settings
LDAPdomain="new_ldap_server_here" # Fully qualified DNS of new LDAP server
oldLDAPdomain="old_ldap_server_here" # Fully qualified DNS of old LDAP server
oldADdomain="olddomain.com" # Fully qualified DNS name of the old Active Directory Domain
oldADdomainname="OLDDOMAIN" # Name of the old AD Domain as specified in the search paths
"Apple Global Domain" = {
AppleAntiAliasingThreshold = 4;
AppleCollationOrder = root;
AppleICUDateTimeSymbols = {
5 = (
AM,
PM
);
};
AppleICUForce24HourTime = 1;
@thom-nic
thom-nic / build.gradle
Last active August 28, 2024 11:24
find the largest classnames in Spring libraries. Also find FactoryFactories
/**
* Find the longest class names in Spring.
* Also find FactoryFactory classes.
* a goof-off project by @thom_nic
*/
import java.util.jar.*
defaultTasks 'longest', 'factoryfactory'
@pudquick
pudquick / exec-priv.sh
Created August 18, 2014 00:14
An example of using execute-with-privileges verb of security command to bypass GUI for a CLI authorization prompt
# This expects that you're already running as sudo'd / root account
cat <<EOF | security -i
authorize -C adminUserNameHere com.apple.uninstalld.uninstall
execute-with-privileges /usr/sbin/uninstall /Applications/SomeMASapp.app
EOF
# In the example above, if you're already running as root / sudo'd admin,
# you still get a prompt for the password of the account in question.
# We aren't dodging proving we know the password - we're just doing it
@raphw
raphw / FieldBenchmark.java
Last active August 20, 2024 10:01
Java MethodHandle and reflection benchmark
package benchmark;
import org.openjdk.jmh.annotations.*;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.TimeUnit;
@thomasdarimont
thomasdarimont / hack.md
Last active February 8, 2025 14:02
This small example demonstrates how to dump the class-files of classes currently loaded in the JVM via jrunscript and internal hotspot API.

Dump loaded classes from another JVM process with Java 9

We will use jrunscript and internal hotspot API to access and export the classfile data. To do that we will use 2 jrunscript processes, a "debuggee" process and a "debugger" jrunscript process. The debugger process will attach to and inspect the debuggee process (internal) via hotspot API. For this example we use the "latest" Java 9 build b41 on OSX.

Motivation for this example was given by the fact that the latest JDK 9 release b41 doesn't ship an rt.jar anymore. The content from rt.jar was now moved to a new platform specific format with the extension .jimage in the JDK_HOME/lib/modules.

You can find more information about the new packaging in Java 9 in Mark Reinholds blogpost: http://mreinhold.org/blog/jigsaw-modular-images

@aaronanderson
aaronanderson / ContainerSecurityFilter.java
Last active March 10, 2018 15:05
JAX-RS 2.0 ContainerRequestFilter that performs the LinkedIn Exchange of JSAPI Tokens for REST API OAuth Tokens
import java.io.IOException;
import java.io.StringReader;
import java.net.URLDecoder;
import java.security.Principal;
import java.util.Base64;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Priority;
@gregsh
gregsh / - IDE Scripting.md
Last active April 18, 2025 16:06
IDE Scripting

Here are my attempts to script an IntelliJ-based IDE using javax.script.* API (ex-JSR-223).

The list of available scripting languages and engines:

  1. Groovy - built-in, via Groovy jars and <app>/lib/groovy-jsr223-xxx.jar
  2. JavaScript (Nashorn) - built-in, via Java Runtime <app>/jbr/... (deprecated and will be removed soon)
  3. JavaScript (GraalJS) - https://plugins.jetbrains.com/plugin/12548-intellij-scripting-javascript
  4. JPython - https://plugins.jetbrains.com/plugin/12471-intellij-scripting-python
  5. JRuby - https://plugins.jetbrains.com/plugin/12549-intellij-scripting-ruby
  6. Clojure - https://plugins.jetbrains.com/plugin/12469-intellij-scripting-clojure
@raphw
raphw / LogInterceptor.java
Created February 23, 2015 14:11
Byte Buddy agent: JDK 8
package introspect;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.AllArguments;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.Origin;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicInteger;
public class LogInterceptor {
apply plugin: 'java'
apply plugin: 'java-library-distribution'
repositories {
mavenCentral()
}
dependencies {
compile 'org.apache.commons:commons-lang3:3.3.2'
}