Skip to content

Instantly share code, notes, and snippets.

View dotSlashLu's full-sized avatar

Zhang Qiang dotSlashLu

View GitHub Profile
@dotSlashLu
dotSlashLu / tabable.js
Created May 26, 2013 13:48
Make textareas able to insert tabs
function tab(event, obj) {
var tabKeyCode = 9;
if (event.which) // mozilla
var keycode = event.which;
else // ie
var keycode = event.keyCode;
if (keycode == tabKeyCode) {
if (event.type == "keydown") {
if (obj.setSelectionRange) {
// mozilla
@dotSlashLu
dotSlashLu / twitter_search.js
Last active January 3, 2016 13:49
Format Twitter feed pages(home, search result) into API format JSON
/**
* Copyright Dotslash.Lu <dotslash.lu@gmail.com>
*
* This script runs on Twitter feed pages(home, search results)
* and automatically get data including both the feed and the user
* then output them in the format of standard API request result
* thus bypassing the limit of the Twitter API
*/
function O(){}
@dotSlashLu
dotSlashLu / fun_hoisting.coffee
Created June 26, 2014 02:38
Coffeescript has a problem with function definition
obj =
test: ->
subfunc()
subfunc = ->
null
// this won't work
var obj = {
test: function() {
subfunc();
var subfunc = function() {};
}
};
// this one works
var obj = {
@dotSlashLu
dotSlashLu / find_in_dir.erl
Last active August 29, 2015 14:21
erlang script to find a file in directories using regular expression
#!/usr/bin/env escript
%% usage: find_in_dir.erl name dir[ dir2[ ...]]
main(P) ->
[For|L] = P,
{ok, Cwd} = file:get_cwd(),
Matches = flatten(lists:map(fun(Dir) ->
Absdir = case Dir of
"" -> Cwd;
[$/|_] -> Dir;
@dotSlashLu
dotSlashLu / install_ovs-dpdk.sh
Last active August 26, 2021 16:52
Prepare, install Open vSwitch and DPDK rpms, and configure OVS
# Install ovs-dpdk
# Copyright Dotslash.Lu <dotslash.lu@gmail.com>
#
# NOTE:
# Please add `iommu=pt intel_iommu=on` to grub bootline and
# reboot
#
# Installation will cause NETWORK LOST, so it's better to
# execute this script within an admin console
#
@dotSlashLu
dotSlashLu / mon.py
Last active September 13, 2017 02:56
waf redis llen monitor
import os
import sys
import time
abspath = os.path.split(os.path.realpath(__file__))[0]
sys.path.append("%s/lib" % abspath)
import redis
import gevent
from gevent import monkey; monkey.patch_all()
@dotSlashLu
dotSlashLu / interchange.c
Created April 19, 2018 08:30
linked list node interchange
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct stack {
int val;
struct stack *next;
};
// find previous node function()
@dotSlashLu
dotSlashLu / main.go
Last active May 9, 2018 09:54
test net unpack
package main
import (
"log"
"fmt"
"net"
"bytes"
"unsafe"
"encoding/binary"
)
@dotSlashLu
dotSlashLu / mon.sh
Created May 24, 2018 08:01
Luminous deploy script
# Usage: bash mon.sh short-hostname
# You should first change the node's hostname, e.g.
# hostnamectl set-hostname mon1.ceph
# Then add it to ~/.ssh/config, e.g.
# Host mon1
dst=$1
ssh $dst systemctl stop firewalld
ssh $dst systemctl disable firewalld