Skip to content

Instantly share code, notes, and snippets.

@limingzju
limingzju / strace.stp
Last active May 28, 2021 02:45
strace.stp
#!/usr/bin/stap
// stap -k -v strace.stp
// https://sourceware.org/systemtap/examples/#process/strace.stp
# suppress some run-time errors here for cleaner output
//bin/true && exec stap --suppress-handler-errors --skip-badvars $0 ${1+"$@"}
/* configuration options; set these with stap -G */
global follow_fork = 0 /* -Gfollow_fork=1 means trace descendant processes too */
global timestamp = 1 /* -Gtimestamp=0 means don't print a syscall timestamp */
@limingzju
limingzju / getdents.stp
Created May 27, 2021 11:48
getdents trace
probe begin
{
log("begin to probe")
}
probe syscall.getdents {
/* process id 123 */
if (pid() == 123) {
file = @cast(task_current(), "task_struct")->files->fdt->fd[$fd]
if (!file)
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
driver = webdriver.Firefox(firefox_profile=profile)
#driver.get("https://10.240.129.198:8443/")
#elem = driver.find_element_by_id("viewer")
#elem.click()
from sympy import *
n, y, u = symbols('n y u')
M = Matrix([[-1*n*y, n*y], [u, -u-(n-1)*y]])
Mt = M.transpose()
X=Matrix([[1,1]])
Y=Matrix([1,0])
m = -X.multiply(Mt.inv()).multiply(Y)
@limingzju
limingzju / path.java
Created May 9, 2015 04:05
spring path variable
@RequestMapping(
value = "/{id}.json",
method = RequestMethod.GET,
produces = "application/json")
@ResponseBody
public Person getDetailsAsJson(@PathVariable Long id) {
return personRepo.findOne(id);
}
@RequestMapping(
@limingzju
limingzju / get.java
Created May 9, 2015 03:49
spring return binary file
@RequestMapping(value="/pdfmethod", produces="application/pdf")
public void pdfMethod(HttpServletRequest request, HttpServletResponse response){
response.setContentType("application/pdf");
InputStream inputStream = null;
OutputStream outputStream = null;
try{
inputStream = getInputStreamFromYourPdfFile();
outputStream = response.getOutputStream();
IOUtils.copy(inputStream, outputStream);
}catch(IOException ioException){
type CopyCb func(written int64)
func CopyWithCb(dst io.Writer, src io.Reader, cb CopyCb) (written int64, err error) {
for {
n, err := io.CopyN(dst, src, KB)
written += n
cb(written)
if err != nil {
if err == io.EOF {
return written, nil
}
import webbrowser
import os
def openWeb(url):
webbrowser.open_new_tab(url)
def main():
urls = ['http://www.baidu.com', 'http://www.bing.com', 'http://www.zhihu.com']
for url in urls:
option = raw_input('open %s Y/N: ' %url)
@limingzju
limingzju / post.go
Created October 20, 2014 02:12
http post
package main
import (
"net"
"fmt"
"io"
"bytes"
"os"
)
import java.net.InetAddress;
import java.net.UnknownHostException;
public class TestNet {
public static void main(String[] args) throws UnknownHostException {
InetAddress[] machines = InetAddress.getAllByName("lbs.yxgslb.netease.com");
for (InetAddress address : machines) {
System.out.println(address.getHostAddress());
}