Skip to content

Instantly share code, notes, and snippets.

@rbe
rbe / PlayWithBits.java
Created August 25, 2012 11:54
Why is this false? Playing with bitwise operators.
int = 12;
boolean b = i == (3 | 6 | 5 | 7 | 32);
@rbe
rbe / BitTest.java
Created August 25, 2012 11:49
Tests with bitwise operator
public class BitTest {
public static void main(String[] args) {
// Der Ausdruck (3 | 6 | 5 | 7 | 32) einzeln aufgelöst:
// (3 | 6) -> 7
System.out.println("( 3 | 6) == 7, ist " + ( 3 | 6));
// (7 | 5) -> 7
System.out.println("( 7 | 5) == 7, ist " + (7 | 5));
@rbe
rbe / NioBufferTest.java
Created August 20, 2012 17:11
Java 7 NIO Buffer Test
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
public class NioBufferTest {
@rbe
rbe / 2_hoch_x.c
Created August 2, 2012 08:59
2^x
#include <stdio.h>
#include <math.h>
#include <assert.h>
void main()
{
int i, x;
printf ( "\n2^x für OS/2." );
printf ( "\nCopyright (C) 1995 von Ralf Bensmann" );
printf ( "\nErstellt in GNU C/C++ für OS/2.");
@rbe
rbe / ascii_to_string.clj
Created July 18, 2012 07:40
ASCII to String
(apply str (map #(char (Integer. %)) (re-seq #"\d+" "‎+++ 83|111|102|116|119|97|114|101|106|111|98|115| +++ ...")))
@rbe
rbe / dis_periodic.sh
Created July 14, 2012 09:06
Oneliner to disable FreeBSD's periodic jobs
grep _enable /etc/defaults/periodic.conf | sed 's#YES#NO#g' > /etc/periodic.conf
@rbe
rbe / apa_enable_log.sh
Created July 14, 2012 07:36
Enable logging directives in Apache virtual server
#!bin/bash
set -o nounset
virtualserver=$1
sed -i -e 's/^[#]\(.*Log .*\)/\1/g' ${virtualserver}
@rbe
rbe / apa_disable_log.sh
Created July 14, 2012 06:44
Disable logging in Apache virtual server
#!bin/bash
set -o nounset
virtualserver=$1
sed -i -e 's/\(^[^#].*Log .*\)/#\1/g' ${virtualserver}
@rbe
rbe / JavaWebFindResource.java
Created June 29, 2012 13:14
Find resources in a web application
// Find resources in e.g. META-INF/resources/tpl/
Set<String> res = getServletContext().getResourcePaths("/tpl/");
if (null != res) {
for (String s : res) {
System.out.println(s);
}
}
@rbe
rbe / GroovyHTTPPost.groovy
Created May 29, 2012 11:38
Groovy HTTP POST
@Grab(group = 'org.codehaus.groovy.modules.http-builder', module = 'http-builder', version = '0.5.0')
import groovyx.net.http.*
def postBody = new File('req.xml').text
def http = new HTTPBuilder('http://localhost:8080/odisee/document/generate')
try {
http.post(path: "generate", body: postBody, requestContentType: groovyx.net.http.ContentType.XML) { resp ->
assert resp.statusLine.statusCode == 200
println resp.statusLine