Skip to content

Instantly share code, notes, and snippets.

View grasses's full-sized avatar
🎯
Focusing

grasses

🎯
Focusing
View GitHub Profile
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from Queue import Queue
import threading, random, time
__author__ = 'homeway'
__version__ = '2015.10.01'
class producer(threading.Thread):
@grasses
grasses / AES-256
Created October 6, 2015 11:45
AES-256 for php, with php module mcrypt, for more see: http://php.net/manual/en/function.mcrypt-encrypt.php
<?php
class MCrypt {
private $hex_iv = '00000000000000000000000000000000'; // converted JAVA byte code in to HEX and placed it here
private $key = 'U1MjU1M0FDOUZ.Qz'; //Same as in JAVA
function __construct() {
$this->key = hash('sha256', $this->key, true);
}
function encrypt($str) {
@grasses
grasses / nfs-server-for-centos
Last active November 11, 2015 02:56
An nfs install script for centos 6
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install nfs"
exit 1
fi
@grasses
grasses / php.fpm
Last active December 11, 2015 03:33
php-fpm controller for mac, please confirm php-fpm is in your $PATH environment.
#!/bin/sh
param=$1
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script."
exit 1
fi
start()
@casualjim
casualjim / WebSocketClient.scala
Created February 13, 2012 19:42
A Netty based WebSocket client and server in scala
package mojolly.io
import org.jboss.netty.bootstrap.ClientBootstrap
import org.jboss.netty.channel._
import socket.nio.NioClientSocketChannelFactory
import java.util.concurrent.Executors
import org.jboss.netty.handler.codec.http._
import collection.JavaConversions._
import websocketx._
import java.net.{InetSocketAddress, URI}
@scutdavy
scutdavy / shell.c
Created December 5, 2013 04:35
unix shell简单实现,支持参数,管道,重定向
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <errno.h>
#define TRUE 1
  1. 开启ipv4转发
vi /etc/sysctl.conf
# 将net.ipv4.ip_forward=0更改为net.ipv4.ip_forward=1
sysctl -p
  1. 安装dnsmasq 和pdnsd解决dns污染

DNS的解析方案为 resolve.conf ==> dnsmasq ==> pdnsd

@cdodd
cdodd / install-squid.sh
Last active June 17, 2022 15:08
Install a basic squid proxy with authentication on Centos 6 x64. Just modify the variables at the top and run the script on a clean system.
#!/bin/sh
PROXY_USER=user
PROXY_PASS=password
PROXY_PORT=3128
# Clear the repository index caches
yum clean all
# Update the operating system
@bortels
bortels / Base64.lua
Created December 6, 2011 05:56
Base64 encode/decode for Codea (Lua)
-- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de>
-- licensed under the terms of the LGPL2
-- character table string
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-- encoding
function enc(data)
return ((data:gsub('.', function(x)
local r,b='',x:byte()
require "try-catch"
try {
function()
error('oops')
end,
catch {
function(error)
print('caught error: ' .. error)