Skip to content

Instantly share code, notes, and snippets.

@pdu
pdu / yaoxuan.py
Created July 6, 2018 15:22
give an array n and integer k, for each element in the array, you have to whether +k or -k. try to find the minimum gap between the largest value and smallest value after the operations
#!/usr/bin/env python
"""
give an array n and integer k, for each element in the array, you have to whether +k or -k
try to find the minimum gap between the largest value and smallest value after the operations
"""
def find1(arr, k):
arr2 = []
for i in xrange(0, len(arr)):
package(default_visibility = ["//visibility:public"])
cc_proto_library(
name = "builtin_service_cc_proto",
deps = [":builtin_service_proto"],
)
proto_library(
name = "builtin_service_proto",
srcs = ["braft/builtin_service.proto"]
@pdu
pdu / stackedit_template.html
Last active June 2, 2017 00:44
The template for publishing articles in wexin_mp, mainly changed the CSS styles.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= documentTitle %></title>
<!--link rel="stylesheet" href="https://stackedit.io/res-min/themes/base.css" /-->
<style type="text/css" media="screen">
/**
* 基于 typo.css 和 Entry.css, 感谢他们
@pdu
pdu / whatsapp_phone_enumerator_floated_div.js
Created May 19, 2017 03:47
PoC WhatsApp enumeration of phonenumbers, profile pics, about texts and online statuses (floated div)
/****** I've created a Chrome extension from this script, take a look at https://github.com/LoranKloeze/WhatsAllApp ********/
/*
PoC WhatsApp enumeration of phonenumbers, profile pics, about texts and online statuses
Floated div edition
01-05-2017
(c) 2017 - Loran Kloeze - loran@ralon.nl
This script creates a UI on top of the WhatsApp Web interface. It enumerates certain kinds
of information from a range of phonenumbers. It doesn't matter if these numbers are part
@pdu
pdu / eat_memory.cpp
Last active February 17, 2017 04:05
Eat memory program, have tested on Mac OSX
#include <stdlib.h>
#include <sys/mman.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char** argv) {
size_t size = atoi(argv[1]) * 1024LL * 1024LL * 1024LL;
printf("%lu\n", size);
void *ptr = malloc(size);
memset(ptr, 0xff, size);
@pdu
pdu / eat_memory.cpp
Created February 17, 2017 04:03
$ g++ eat_memory.cpp -o eat_memory
#include <stdlib.h>
#include <sys/mman.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char** argv) {
size_t size = atoi(argv[1]) * 1024LL * 1024LL * 1024LL;
printf("%lu\n", size);
void *ptr = malloc(size);
memset(ptr, 0xff, size);
@pdu
pdu / iscsid_mgmt_ipc.c
Last active December 21, 2015 06:39
remove conn of iscsid
static mgmt_ipc_err_e
mgmt_ipc_conn_remove(queue_task_t *qtask)
{
int sid = -1, cid = -1;
iscsi_session_t *session;
iscsi_conn_t *conn;
int err = MGMT_IPC_OK;
sid = qtask->req.u.conn.sid;
cid = qtask->req.u.conn.cid;
@pdu
pdu / isPidExist.py
Created April 12, 2013 01:24
python判断一个进程是死是活,kill 0不真正发送信号,但是会检查进程的错误。http://linux.die.net/man/2/kill
import os, errno
def isExist(pid):
try:
os.kill(pid, 0)
return True
except OSError, e:
if e.errno == errno.ESRCH:
return False
else
@pdu
pdu / leetcode_divide_two_integers.cpp
Created February 21, 2013 14:18
Divide two integers without using multiplication, division and mod operator. http://leetcode.com/onlinejudge#question_29
long long f[32];
long long g[32];
class Solution {
public:
int divide(int dd, int dr) {
long long divisor = dr, dividend = dd;
int flag = 1;
if (divisor < 0) {
divisor = -divisor;
flag *= -1;
@pdu
pdu / leetcode_substring_with_concatenation_of_all_words.cpp
Created February 21, 2013 14:05
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening characters. For example, given: S: "barfoothefoobarman" L: ["foo", "bar"] You should return the indices: [0,9]. (order does not matte…
#define MAXN 10000
int f[MAXN];
int flag[MAXN];
int num[MAXN];
class Solution {
public:
vector<int> findSubstring(string S, vector<string> &L) {
memset(f, -1, sizeof(f));
int m = S.length();