Skip to content

Instantly share code, notes, and snippets.

@allen501pc
allen501pc / Multi-Threads_Jobs_in_Hadoop.java
Created July 2, 2011 09:14
Multi-Threads Jobs in Hadoop
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
import java.io.DataInput;
@allen501pc
allen501pc / Cal.cpp
Created September 5, 2011 08:22
教育部專用計算程式
#include <iostream>
using namespace std;
/* 總金額 */
#define _SUM_OF_DOLLARS 20800
/* Dollars of Item 1. */
#define _ITEM_1 170
/* Dollars of Item 2. */
#define _ITEM_2 870
int main(int argc, char * argv[])
@allen501pc
allen501pc / CountWord.cpp
Created September 27, 2011 15:11
Count Words and Sort It!
/*
* Program Description:
* Count the input data character frequence, and store the characters which are composed with 'A-Z' or 'a-z'.
* And output the character and respective frequency. Note that the characters 'A-Z' and 'a-z' are the same.
* For example,
* Input:
* This is a text for Q2.
* My cellphone number is 123-456-789.
* E-mail: allen501pc@gmail.com
Output:
@allen501pc
allen501pc / Q3.cpp
Created September 27, 2011 19:54
找最長的回文子字串,並顯示出其長度
/*
Ex: Given
10
1 2 3 4 5 8 4 3 2 1
Note that the first line is the counts of numbers in the second lines.
Then, we can find that the max_seq = '1 2 3 4 5 4 3 2 1', whose length = 9.
*/
#include <iostream>
@allen501pc
allen501pc / find_substring_from_stream.cpp
Created October 31, 2011 10:20
Find string from stream
/* Program: Find the character substring location of the input character string.
* Author: Jyun-Yao Huang (allen501pc@gmail.com)
* License: Free
*/
#include <iostream>
#include <bitset>
#include <string>
#include <set>
#include <vector>
@allen501pc
allen501pc / 在MVC3上包JSON物件_送給Controller的方法.js
Created December 29, 2011 06:53
在MVC 3上包JSON物件,送給Controller的方法
$.ajax({
type: "POST", /* 選擇傳輸方式 */
url: "/person/create", /*選擇要處理的controller/action */
dataType: "json", /*選擇資料類型,以本篇文章,資料類型為json */
contentType: "application/json; charset=utf-8", /* 選擇傳輸的encoding以及媒體類型 */
data: jsonData, /* data欄位填入json包好的資料就行了!以這個為例,jsonData是該篇文章的一個物件 */
success: function (result){ /* 成功了要做什麼動作? */
console.log(result); //log to the console to see whether it worked
},
error: function (error){ /* 失敗了要做什麼動作? */
@allen501pc
allen501pc / ASP.NET- 從web.config中取得檔案上傳下載目錄設定.cs
Created December 29, 2011 10:05
ASP.NET- 從web.config中取得檔案上傳下載目錄設定
/* 要使用 ConfigurationManager,需引入System.Configuration 這個namespace */
using System.Configuration;
/* 程式碼區 */
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
//檢查是否有檔案上傳,有的話存檔
if (file !=null && file.ContentLength > 0)
@allen501pc
allen501pc / 函數傳遞Array Reference.cpp
Created December 31, 2011 08:29
函數傳遞Array Reference
/*
* @Function: void fnPrintArray(int arr[10])
* @Brief: Print the array content , and the input is by reference.
* @Input: int arr[10]
* @Output: array content.
*/
void fnPrintArray(int (&arr)[10])
{
for(size_t i=0;i<10;++i)
{
@allen501pc
allen501pc / 用2維陣列template傳遞不定大小陣列Array.cpp
Created December 31, 2011 08:34
用2維陣列template傳遞不定大小陣列Array
#include <iostream>
using namespace std;
/*
* @Function:
template<typename T,size_t M,size_t N>
void fnPrint2DArray(T (&arr)[M][N])
* @Brief: Print the content of 2D Array.
* @Input: 2D array.
* @Output: None.
*/
@allen501pc
allen501pc / 在template中使用typename.cpp
Created December 31, 2011 08:38
在template中使用typename
template<typename T>
class A{
public:
T m_A;
void funcTest()
{
map<T , int> mapTempTable; /* 這部分沒問題, OK! */
/* 編譯器會出錯!
要改成 typename map<T, int>::iterator it; */
map<T, int>::iterator it;