Skip to content

Instantly share code, notes, and snippets.

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import static com.google.common.base.Preconditions.checkNotNull;
public class FileSystemLock {
private final File lockFile;
#! /usr/bin/env python3
""" Cleaning script based on .gitignore file, the 'find' and 'rm' command.
It removes files with .gitignore pattern.
This script reads the .gitignore file, parses the patterns found there to a
shell remove command and then executes it.
- With the 'dirs' option it also removes directories.
- With the 'debug' option it just prints the command it would execute and exits.
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
#!/bin/sh
# Pre-commit hook that crushes PNG files in order to reduce their size.
if ! which -s pngcrush
then
echo "Please install pngcrush to reduce png images size before commit"
exit 1;
fi
for file in `git diff --cached --name-only | grep ".png\$"`
@pudney
pudney / _mvn
Created June 9, 2010 17:11
Zsh Completion Function for Maven
#compdef mvn
_mvn_targets () {
local -a commands
commands=('jetty\:run:Run Jetty from the current context.' 'validate:validate the project is correct and all necessary information is available' 'compile:compile the source code of the project' 'test:test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed' 'package:take the compiled code and package it in its distributable format, such as a JAR.' 'integration-test:process and deploy the package if necessary into an environment where integration tests can be run' 'verify:run any checks to verify the package is valid and meets quality criteria' 'install:install the package into the local repository, for use as a dependency in other projects locally' 'deploy:done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.' 'clean:remove all files generated by the previous build')
_describe -t commands
// Newbie programmer
int factorial_newbie(int n) {
if (n == 0) {
return 1
} else {
return n * factorial_newbie(n - 1)
}
}
println factorial_newbie(6)
@tuor713
tuor713 / ObjectSizer
Created July 21, 2011 19:16
Calculating total size of Java object graph
import java.lang.instrument.Instrumentation;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.IdentityHashMap;
public class ObjectSizer {
private static Instrumentation instrumentation;
@buzztaiki
buzztaiki / PermDetail.java
Created September 29, 2011 17:25
print permgen details
import java.util.*;
import java.io.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.memory.*;
import sun.jvm.hotspot.oops.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.tools.*;
import sun.jvm.hotspot.utilities.*;
@shyiko
shyiko / intellij-idea-jd-gui-launcher.sh
Created November 12, 2011 09:27
JD-GUI Launcher for Intellij IDEA (via External Tools)
#!/bin/bash
JDGUI_BIN=$1; FILE_PATH=$2
DELIMITER_INDEX=$(awk -v a="$FILE_PATH" -v b="!/" 'BEGIN{print index(a,b)}')
if [ $DELIMITER_INDEX -eq 0 ]; then
$JDGUI_BIN $FILE_PATH
else
JAR_FILE=${FILE_PATH:0:$DELIMITER_INDEX-1}
CLASS_RELATIVE_LOCATION=${FILE_PATH:$DELIMITER_INDEX+1}
if [[ $CLASS_RELATIVE_LOCATION == "" ]]; then
$JDGUI_BIN $JAR_FILE
@radupotop
radupotop / fonts.conf.xml
Created March 10, 2012 20:46
fonts.conf
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<!-- http://ubuntuforums.org/showthread.php?t=1354116 -->
<fontconfig>
<!-- See: man 5 fonts-conf -->
<!-- Antialias rules -->
<match target="font">
<!--Subpixel smoothing: rgb, bgr, vrgb, vbgr, none-->
<edit mode="assign" name="rgba"><const>none</const></edit>