Skip to content

Instantly share code, notes, and snippets.

View ggrandes's full-sized avatar
🛠️
I may be slow to respond.

G.Grandes ggrandes

🛠️
I may be slow to respond.
View GitHub Profile
@stfp
stfp / SelfKiller.java
Created May 19, 2011 03:21
Java class to kill the current process using JNA
/* Requires JNA
* Get jna.jar here: http://java.net/projects/jna/sources/svn/show/trunk/jnalib/dist
*/
import com.sun.jna.Library;
import com.sun.jna.Native;
public class SelfKiller
{
private interface CLibrary extends Library
{
@isopov
isopov / NettyTest.java
Created July 12, 2011 09:52
Problem with sending/receiving Http POST request with Netty (solved)
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
import static org.jboss.netty.handler.codec.http.HttpResponseStatus.OK;
import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
import java.util.concurrent.Executors;
import junit.framework.Assert;
@isopov
isopov / KeepAliveLocalhostTest.java
Created July 16, 2011 20:52
Simple bench comparing creating new connection per each HttpRequest and using one keep-alive connection (Based on Netty)
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.charset.Charset;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.bootstrap.ServerBootstrap;
@ayosec
ayosec / LibC.java
Created December 24, 2011 01:41
LibC binding with JNA
package com.ayosec.misc;
import com.sun.jna.*;
public class LibC {
public interface Handle extends Library {
Handle module = (Handle) Native.loadLibrary("c", Handle.class);
int getpid();
@witscher
witscher / tomcat.conf
Created June 13, 2012 13:24
Apache Tomcat Upstart script
description "Tomcat Server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
# run as non privileged user
# add user with this command:
## adduser --system --ingroup www-data --home /opt/apache-tomcat apache-tomcat
@earthgecko
earthgecko / bash.generate.random.alphanumeric.string.sh
Last active June 21, 2024 07:34
shell/bash generate random alphanumeric string
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1
@chixq
chixq / sigar.java
Created May 21, 2013 06:19
java system monitor using sigar
import java.util.ArrayList;
import java.util.List;
import org.hyperic.sigar.CpuInfo;
import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.cmd.Ps;
@ggrandes
ggrandes / tomcat7-deploy.sh
Last active March 6, 2022 16:52
Automatic Deploy of Apache Tomcat (7.0.x; DEPRECATED; EOL 31/03/2021) and Log4J (1.2.x) (Linux)
#!/bin/bash
# Licensed 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@JamesMGreene
JamesMGreene / gitflow-breakdown.md
Last active June 22, 2024 03:44
`git flow` vs. `git`: A comparison of using `git flow` commands versus raw `git` commands.

Initialize

gitflow git
git flow init git init
  git commit --allow-empty -m "Initial commit"
  git checkout -b develop master

Connect to the remote repository

@chrisveness
chrisveness / base64.js
Last active May 6, 2023 02:55
Encode/decode ASCII string to/from base64
/**
* Encode string into Base64, as defined by RFC 4648 [http://tools.ietf.org/html/rfc4648].
* As per RFC 4648, no newlines are added.
*
* Characters in str must be within ISO-8859-1 with Unicode code point <= 256.
*
* Can be achieved JavaScript with btoa(), but this approach may be useful in other languages.
*
* @param {string} str ASCII/ISO-8859-1 string to be encoded as base-64.
* @returns {string} Base64-encoded string.