Skip to content

Instantly share code, notes, and snippets.

View Jimmy-Xu's full-sized avatar

Jimmy Xu Jimmy-Xu

  • Ant Group
  • Beijing, China
View GitHub Profile
@Jimmy-Xu
Jimmy-Xu / test.log
Created September 27, 2017 11:06
test.log
[BEGIN] 2017/9/27 17:57:30
cat test.log
HOSTNAME=cbd7d8772e27
TERM=xterm
@Jimmy-Xu
Jimmy-Xu / simple-exec-with-docker-remote-api.sh
Created September 7, 2017 13:35 — forked from markjlorenz/simple-exec-with-docker-remote-api.sh
Using the exec command with the docker API, and capturing output
#! /usr/bin/env bash
# Create the container with a long running process. If PID1 exists before
# we send the exec commands, they will fail because the container is not running
#
CONTAINER_NAME="TEST-`uuidgen`"
curl --silent --unix-socket /var/run/docker.sock "http:/containers/create?name=${CONTAINER_NAME}" -XPOST \
-H "Content-Type: application/json" \
-d '{
"Image": "ruby:latest",
@Jimmy-Xu
Jimmy-Xu / setup-bridge.sh
Created June 29, 2017 09:23 — forked from ismell/setup-bridge.sh
Scripts to re-create the docker0 bridge and setup a different ip subnet
#!/bin/bash -e
IFADDR="192.168.3.1/24"
if [[ ! ip link show docker0 ]]; then
ip link add docker0 type bridge
ip addr add "$IFADDR" dev docker0
ip link set docker0 up
iptables -t nat -A POSTROUTING -s "$IFADDR" ! -d "$IFADDR" -j MASQUERADE
fi
@Jimmy-Xu
Jimmy-Xu / pxe-vm.sh
Created June 12, 2017 09:28 — forked from gdamjan/pxe-vm.sh
A script to start a qemu-kvm virtual machine that boots from PXE (it'll configure a bridge and add eth0 to it)
#!/bin/bash
MEM=1024
LAN=eth0
BRIDGE=virtbr
ARCH=x86_64 # i386
#BIOS="-bios OVMF.fd" # to emulate an UEFI netboot
# supported wifi interfaces can be bridged if you set 4addr mode first:
# iw dev $LAN set 4addr on
package main
import "net"
func echoServer(c net.Conn) {
for {
buf := make([]byte, 512)
nr, err := c.Read(buf)
if err != nil {
return
@Jimmy-Xu
Jimmy-Xu / connect-qemu-serial.sh
Created April 5, 2017 08:22 — forked from nlm/connect-qemu-serial.sh
Connect to QEMU unix socket serial port
#!/bin/sh
SOCKDIR="/var/lib/qemu/sockets"
HOSTNAME="$1"
if [ -z "$HOSTNAME" ]
then
echo "usage: $0 HOSTNAME" >&2
exit 1
fi
@Jimmy-Xu
Jimmy-Xu / get-parent-process.psm1
Last active April 1, 2017 14:48
递归获取父进程
#usage:
# Import-Module ./get-parent-process.psm1 -Force
## example
# Get-ParentProcess -Name CExecSvc
# Get-ChildProcess -Name CExecSvc
function Get-ParentProcess {
[cmdletbinding()]
param(
[parameter(mandatory=$true,position=1)][string]$Name
@Jimmy-Xu
Jimmy-Xu / nginx.conf
Created March 9, 2017 01:14 — forked from Stanback/nginx.conf
Example Nginx configuration for adding cross-origin resource sharing (CORS) support to reverse proxied APIs
#
# CORS header support
#
# One way to use this is by placing it into a file called "cors_support"
# under your Nginx configuration directory and placing the following
# statement inside your **location** block(s):
#
# include cors_support;
#
# As of Nginx 1.7.5, add_header supports an "always" parameter which
@Jimmy-Xu
Jimmy-Xu / windows10qemu.sh
Created February 8, 2017 13:49 — forked from Manouchehri/windows10qemu.sh
Running Windows 10 in a UEFI enabled QEMU environment with KVM.
# Installing
qemu-system-x86_64 -bios /usr/share/ovmf/ovmf_x64.bin -enable-kvm -cpu host -smp 4 -m 2048 -cdrom ~/Downloads/Win10_English_x64.iso -net nic,model=virtio -net user -drive file=~/vm/win10.hd.img.raw,format=raw,if=virtio -vga qxl -drive file=~/Downloads/virtio-win-0.1.105.iso,index=1,media=cdrom
# Running
qemu-system-x86_64 -bios /usr/share/ovmf/ovmf_x64.bin -enable-kvm -cpu host -smp 4 -m 4096 -net nic,model=virtio -net user -drive file=~/vm/win10.hd.img.raw,format=raw,if=virtio -vga qxl -usbdevice tablet -rtc base=utc
@Jimmy-Xu
Jimmy-Xu / mb_substr_replace.php
Created January 19, 2017 05:18 — forked from stemar/mb_substr_replace.php
Multibyte substr_replace(). The mbstring library doesn’t come with a multibyte equivalent of substr_replace(). This function behaves exactly like substr_replace() even when the arguments are arrays.
<?php
function mb_substr_replace($string, $replacement, $start, $length=NULL) {
if (is_array($string)) {
$num = count($string);
// $replacement
$replacement = is_array($replacement) ? array_slice($replacement, 0, $num) : array_pad(array($replacement), $num, $replacement);
// $start
if (is_array($start)) {
$start = array_slice($start, 0, $num);
foreach ($start as $key => $value)