Skip to content

Instantly share code, notes, and snippets.

@mengdiwang
mengdiwang / llvm_build
Created February 26, 2014 03:29
configure and make llvm for cloud9
./configure --enable-optimized --enable-assertions --enable-expensive-checks
CXXFLAGS+="-fexceptions" make -j3
@mengdiwang
mengdiwang / dateformat.js
Created March 30, 2014 15:17
Date format for javascript
Date.prototype.format = function(format)
{
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
@mengdiwang
mengdiwang / cs
Created May 6, 2015 06:41
learning
python http://v.163.com/special/opencourse/bianchengdaolun.html
#解决Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
@mengdiwang
mengdiwang / lc_141.cpp
Created October 30, 2015 19:17
Linked List Cycle
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
@mengdiwang
mengdiwang / lc_268.cpp
Created October 30, 2015 19:26
Missing Number
class Solution {
public:
int missingNumber(vector<int>& nums) {
int sum = 0;
for(int i=0; i<nums.size(); i++)
{
sum += nums[i];
}
return (1+nums.size())*nums.size()/2 - sum;
}
@mengdiwang
mengdiwang / lc_116.cpp
Created October 30, 2015 21:12
Populating Next Right Pointers in Each Node
/**
* Definition for binary tree with next pointer.
* struct TreeLinkNode {
* int val;
* TreeLinkNode *left, *right, *next;
* TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}
* };
*/
class Solution {
public:
@mengdiwang
mengdiwang / lc_96.cpp
Created October 30, 2015 21:57
Unique Binary Search Trees
class Solution {
public:
int numTrees(int n) {
if(n<=1) return 1;
int *a = new int[n+1];
memset(a, 0, sizeof(int)*(n+1));
a[1] = 1;
a[0] = 1;
for(int i=2; i<=n; i++)
{
@mengdiwang
mengdiwang / searchInsert.cpp
Created November 1, 2015 05:16
searchInsert
class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int lo = 0;
int hi = nums.size()-1;
while(lo<=hi)
{
int mid = ((lo-hi)>>1) + hi;
if(nums[mid] == target)
return mid;
#List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
#Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
#Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(value_list)]