Skip to content

Instantly share code, notes, and snippets.

View xurenlu's full-sized avatar
🎆
holiday

黄滚 xurenlu

🎆
holiday
View GitHub Profile
#! /bin/bash
#设置console的颜色
TPUT=/usr/bin/tput
RED=`$TPUT setaf 1`
GREEN=`$TPUT setaf 2`
YELLOW=`$TPUT setaf 3`
NORM=`$TPUT op`
HOSTFILE=~/.sshhosts
#输出红色文字,错误提示用
@xurenlu
xurenlu / myjson.php
Created May 25, 2011 08:56
simple json decode
<?php
//将内容进行UNICODE编码
function unicode_encode($name)
{
$name = iconv('UTF-8', 'UCS-2', $name);
$len = strlen($name);
$str = '';
for ($i = 0; $i < $len - 1; $i = $i + 2)
{
@xurenlu
xurenlu / encrypt.php
Created September 7, 2011 07:12
加密解析
<?php
function strToHex($string)
{
$hex="";
for ($i=0;$i<strlen($string);$i++)
$hex.=dechex(ord($string[$i]));
$hex=strtoupper($hex);
return $hex;
}
function hexToStr($hex)
@xurenlu
xurenlu / backup.sh
Created October 10, 2011 10:28
bash进行目录检查和备份
#!/bin/bash
#param 1: the name of the configuration
#param 2: the path to backup
back_dir_prefix="/home/x/back/"
back_up(){
name=$1
path=$2
echo $name " => " $path
last_back_dir="${back_dir_prefix}${name}"
@xurenlu
xurenlu / try_to_run_once.sh
Created October 14, 2011 14:31
运行一次
#!/bin/bash
# check daemon
check(){
cmd=$1
lines=`ps -ef | grep $cmd |grep -v grep |wc -l`
# if not found - equals to 1, start it
echo $lines
if [ $? -eq 0 ]; then
$cmd
else
@xurenlu
xurenlu / s.sh
Created October 14, 2011 14:32
ssh机器管理
#! /bin/bash
#设置console的颜色
TPUT=/usr/bin/tput
RED=`$TPUT setaf 1`
GREEN=`$TPUT setaf 2`
YELLOW=`$TPUT setaf 3`
NORM=`$TPUT op`
HOSTFILE=~/.sshhosts
#输出红色文字,错误提示用
@xurenlu
xurenlu / php_errlog.php
Created December 1, 2011 06:32
php errorlog modify
<?php
register_shutdown_function('handleShutdown');
function handleShutdown() {
$error = error_get_last();
if($error !== NULL){
$info = "[SHUTDOWN] file:".$error['file']." | ln:".$error['line']." | msg:".$error['message'] .PHP_EOL;
$sapi_type = php_sapi_name();
$sapi = substr($sapi_type, 0, 3);
if($sapi=="cli"){
$info .= join(" ",$_SERVER["argv"]);
@xurenlu
xurenlu / send_to_my_mail.py
Created December 6, 2011 15:43
send to my mail from input
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#导入smtplib和MIMEText
import smtplib
from email.mime.text import MIMEText
#############
#要发给谁,这里发给2个人
#####################
#设置服务器,用户名、口令以及邮箱的后缀
mail_host="smtp.****.com"
@xurenlu
xurenlu / walker.php
Created December 14, 2011 09:54
walk walk and walk
<?php
/**
* 遍历某个目录或某个目录用;
* 只需设置回调即可;
* */
class Walker{
var $dir;
var $callback=null;
var $num = 0;
var $ecode=0;
@xurenlu
xurenlu / gist:1875087
Created February 21, 2012 08:18
html 5 桌面消息.
<!DOCTYPE HTML>
<html>
<head>
<title>Creating OS notifications in HTML5</title>
</head>
<body>
<form>
<input type="button" value="Hey, do you want to show notifications or not?" onclick="init();" />
<input type="button" value="Send OS notification" onclick="notify();" />