Skip to content

Instantly share code, notes, and snippets.

@wfwei
wfwei / inrange.perl
Created December 2, 2016 08:55
in range function in perl
#
# Hello World Program in Perl
#
print "\nHello World!\n";
sub inRange
{
(my $var,my @rng)=@_;
@wfwei
wfwei / entropy.scala
Last active February 2, 2016 03:16
entropy
def entropy(x:Double, y:Double):Double = {
if(x==0 || y==0){
0
} else {
val p1 = x / (x + y)
val p2 = y / (x + y)
- (p1*math.log(p1) + p2*math.log(p2))/math.log(2)
}
}
@wfwei
wfwei / js-code.js
Created September 14, 2015 02:31
js-code
document.addEventListener('click', function(e) { console.log(
'page: ' + e.pageX + ',' + e.pageY,
'client: ' + e.clientX + ',' + e.clientY,
'screen: ' + e.screenX + ',' + e.screenY) }, false);
@wfwei
wfwei / eva.py
Created January 6, 2014 09:42 — forked from anonymous/eva.py
# !/usr/bin/python
# -*- coding: utf-8 -*-
import math
def prf(tlist, plist, n):
'''
cal the (precision, recall, f-score)
rlist:real values list
import java.util.Scanner;
import java.util.Stack;
public class MaxArea {
public static int maxArea(int[] heights) {
int max = Integer.MIN_VALUE;
Stack<Integer> inc = new Stack<Integer>();
for (int i = 0; i < heights.length; i++) {
while (!inc.isEmpty() && heights[inc.peek()] > heights[i]) {
@wfwei
wfwei / containers.cpp
Created October 9, 2013 14:24
basic operations of c++ containers
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
static int cmp(int a, int b) {
return a > b;
}
@wfwei
wfwei / ReverseInsert.java
Created October 5, 2013 11:48
将1->2->3->4->5->6->7 变成 1->7->2->6->3->5->4,recursive解法
package mine.coding;
public class ReverseInsert {
private static class Node {
public int val;
public Node next;
public Node(int val) {
this.val = val;
@wfwei
wfwei / crawler.py
Last active December 24, 2015 04:09
#!/usr/bin/python
# coding:utf-8
import urllib2
import BeautifulSoup
import re
import os
HOST = u'http://www.washingtonpost.com/'
image_patt = re.compile('.*photo-wrapper')
import java.util.Scanner;
public class Main {
static int sumTime(int[] arr, int upcost, int downcost, int stopcost){
int up=arr[0], down=0, stop=arr.length;
for(int i=1; i<arr.length; i++){
int diff = arr[i] -arr[i-1];
if(diff>0)
@wfwei
wfwei / pack.cpp
Created August 26, 2013 14:59
背包问题(01背包 完全背包 多重背包)的解法,参考背包9讲的思路
//============================================================================
// Name : Coding.cpp
// Author : Plex
// Version : 1.0
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <string>
#include <string.h>