Skip to content

Instantly share code, notes, and snippets.

@allen501pc
allen501pc / URLEncryptor.php
Created May 5, 2012 07:27
[PHP] Url encryptor
<?php
/* Function: ImageURLEncryption
* Parameters:
* $Url : the url or text that you want to encrypt.
* $Code: the magic code which masks the url.
*/
function ImageURLEncryption($Url,$Code)
{
$SecretCode = md5($Code);
@allen501pc
allen501pc / Invert List.cpp
Created April 18, 2012 11:24
反轉議程委員表,把它轉換為 Name, Review No 1~Review No. n.
/* Author: Allen (allen501pc@gamil.com)
* Date: 2012/04/18 18:30
* Goal: 反轉委員表,把它轉換為 Name, Review No 1~Review No. n.
*/
#include <iostream>
#include <fstream>
#include <string>
#include <iterator>
#include <map>
@allen501pc
allen501pc / C++ Read Configuration.cpp
Created December 31, 2011 08:42
C++ Read Configuration
ConfigFile cf("config.txt");
std::string foo;
std::string water;
double four;
foo = cf.Value("section_1","foo" );
water = cf.Value("section_2","water");
four = cf.Value("section_2","four" );
@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;
@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傳遞不固定Size之陣列給Function.cpp
Created December 31, 2011 08:31
用template傳遞不固定Size之陣列給Function
#include <iostream>
using namespace std;
/*
* @Function:
template<typename T,size_t N>
void fnChange(T (&arr)[N])
* @Brief: Let each element of array increase by one.
* @Input: 1D array
* @Output: The array whose elements all increase by 1
@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 / 函數傳遞固定大小的陣列.cpp
Created December 31, 2011 08:27
函數傳遞固定大小的陣列
/*
* @Function: void fnPrintArray(int arr[10])
* @Brief: Print the array content.
* @Input: int arr[10]
* @Output: array content.
*/
void fnPrintArray(int arr[10])
{
for(size_t i=0;i<10;++i)
{
@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 / 在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){ /* 失敗了要做什麼動作? */