Skip to content

Instantly share code, notes, and snippets.

java.util.Date utilDate = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
public static void fileCopy( File in, File out )
throws IOException
{
FileChannel inChannel = new FileInputStream( in ).getChannel();
FileChannel outChannel = new FileOutputStream( out ).getChannel();
try
{
// magic number for Windows, 64Mb - 32Kb)
int maxCount = (64 * 1024 * 1024) - (32 * 1024);
long size = inChannel.size();
File dir = new File("directoryName");
String[] children = dir.list();
if (children == null) {
// Either dir does not exist or is not a directory
} else {
for (int i=0; i < children.length; i++) {
// Get filename of file or directory
String filename = children[i];
}
}
//Sample XML file
/*
<?xml version="1.0"?>
<students>
<student>
<name>John</name>
<grade>B</grade>
<age>12</age>
</student>
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL my_url = new URL("http://www.viralpatel.net/blogs/");
BufferedReader br = new BufferedReader(new InputStreamReader(my_url.openStream()));
String strTemp = "";
/**
* Reallocates an array with a new size, and copies the contents
* of the old array to the new array.
* @param oldArray the old array, to be reallocated.
* @param newSize the new array size.
* @return A new array with the same contents.
*/
private static Object resizeArray (Object oldArray, int newSize) {
int oldSize = java.lang.reflect.Array.getLength(oldArray);
Class elementType = oldArray.getClass().getComponentType();
@nandub
nandub / gist:222969
Created October 31, 2009 07:27
git add commit push
#!/bin/bash
export MESSAGE=$1
export BRANCH=$2
if [ "$MESSAGE" == "" ]
then
echo "Usage $0 commit-message"
exit 1
fi
export MESSAGE="${MESSAGE}"
@nandub
nandub / git-pull-all.bash
Created September 4, 2010 02:24
Simple bash script to update all git-clone repos from a local directory
#!/bin/bash
f=$(pwd) # 'pwd' is "present working directory"
FOLDERS=`ls -d $f/*`
for f in $FOLDERS
do
if [ -d "$f/.git" ]; then
pushd $f
git pull
@nandub
nandub / values.c
Created September 24, 2010 20:24
Solaris x86 specific GCC run-time environment patch
#if 0
#
# This is Solaris x86 specific GCC run-time environment patch, which
# makes it possible to reliably deploy .init snippets. Trouble is that
# Solaris linker erroneously pads .init segment with zeros [instead of
# nops], which is bound to SEGV early upon program start-up. This bug
# was recognized by GCC team [it is mentioned in source code], but
# workaround apparently and obviously erroneously slipped away in some
# newer GCC release. This patch compensates for this mishap by dropping
# modified values-X*.o into GCC installation tree. Object modules in
@nandub
nandub / ath5-2.6.38-8-natty-fix
Created August 25, 2011 23:46
Kernel 2.6.38.8: ath5k driver wireless signalstrength critically weak - Natty workaround fix
#!/bin/bash
#Got this solution from http://fossplanet.com/f10/%5Bbug-775104%5D-%5Bnew%5D-kernel-2-6-38-8-ath5k-driver-wireless-signalstrength-critically-weak-148704/ by salemboot
apt-get install subversion
cd /usr/src
svn checkout http://madwifi-project.org/svn/madwifi/trunk madwifi
tar cfvz madwifi.tgz
cd madwifi
make && make install