Skip to content

Instantly share code, notes, and snippets.

@maddingo
maddingo / alarm.sh
Created July 30, 2025 07:38
alarm script dimming the screen and showing a message on linux
#!/bin/bash
# Bash version of https://askubuntu.com/a/464683
declare -a screens
screens+=($(xrandr | awk '/ connect/{print $1}' | xargs))
message="${1:-"Alarm triggered!"}"
echo "Alarm message: ${message}"
exit 0
@maddingo
maddingo / solrdelete.bat
Last active December 17, 2015 08:49
Little *.bat file that deletes all documents on a given Solr core. It required curl
@echo off
SET creds=ServiceSolrUpdate:8zpQUxQ5
SET ct="Content-Type: text/xml"
SET q="<delete><query>*:*</query></delete>"
SET u=http://search-server.uis.no/solr
for %%c in ( student-en student-nb student-nn studinfo-en studinfo-nb studinfo-nn ) do curl --basic -u %creds% -H %ct% --data-binary %q% %u%/%%c/update?commit=true
@maddingo
maddingo / EntityManager.java
Created February 1, 2013 14:13
Code for parsing XML with uncomplete entities (&)
package no.uis.service.fsimport.impl;
import java.io.IOException;
import org.apache.xerces.impl.Constants;
import org.apache.xerces.impl.XMLEntityManager;
import org.apache.xerces.impl.XMLEntityScanner;
public class EntityManager extends XMLEntityManager {
@maddingo
maddingo / dirty.xml
Created December 19, 2012 07:34 — forked from anonymous/dirty.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
<url>See http://www.uis.no</url>
</root>
@maddingo
maddingo / xml-to-spring.xsl
Created August 3, 2012 11:56
XSLT for XML to Spring beans conversion
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fs="http://fsws.usit.no/schemas/studinfo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:functx="http://www.functx.com"
exclude-result-prefixes="xs fs functx"
@maddingo
maddingo / JettyTestRunner.java
Created May 30, 2012 08:33
Junit4 TestRunner for Jetty 6
package no.uis.service.fsimport;
import static org.junit.Assert.*;
import java.io.File;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@maddingo
maddingo / partial_server.xml
Created May 9, 2012 11:09
Tomcat7 server.xml JNDI Resource
<!-- This is the Realm definition for Active Directory Don't forget to put the server's certificate in Tomcat's keystore -->
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm"-->
<Realm className="org.apache.catalina.realm.JNDIRealm"
connectionURL="ldaps://ad01.uis.no"
connectionName="THE_FULL_USER_DN_OF_THE_AD_USER"
connectionPassword="THE_PASSWORD"
userBase="DC=uis,DC=no"
adCompat="true"
userSubtree="true"
@maddingo
maddingo / web.xml
Created May 9, 2012 11:05
Tomcat7 web.xml for Solr
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
@maddingo
maddingo / gist:2487779
Created April 25, 2012 07:34
Example for using HttpClientFactory in spring
<bean id="httpClient" class="no.uis.service.fsimport.util.PreemptBasicAuthHttpClient">
<constructor-arg index="0" value="${solr.server.url}"/>
<constructor-arg index="1" value="${solr.server.username}"/>
<constructor-arg index="2" value="${solr.server.password}"/>
</bean>
<bean id="solrServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg index="0" value="${solr.server.url}"/>
<constructor-arg index="1" ref="httpClient"/>
<constructor-arg index="2">
@maddingo
maddingo / HttpClientFactory.java
Created April 25, 2012 07:32
Solr Http Client authentication with solrj-3.6.0 and httpclient-4.1.2 (usage see https://gist.github.com/2487779)
package no.uis.service.fsimport.util;
import java.net.URL;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.impl.auth.BasicScheme;