Skip to content

Instantly share code, notes, and snippets.

View ccckmit's full-sized avatar

陳鍾誠 ccckmit

View GitHub Profile
@ccckmit
ccckmit / gist:b0a90a7bd9d3d3e5baa8
Last active August 29, 2015 14:16
javascript version of enigma machine (in world war II)
// 原始程式來源: http://practicalcryptography.com/ciphers/enigma-cipher/ 網頁內的 javascript 程式碼
var c = console;
var plaintext = 'ABCDEF';
c.log('>> plaintext2 : '+plaintext);
var ciphertext = Encrypt(plaintext, 'AAA', 'AAA', '123', 'POMLIUKJNHYTGBVFREDC');
c.log('>> ciphertext : '+ciphertext);
var plaintext2 = Encrypt(ciphertext, 'AAA', 'AAA', '123', 'POMLIUKJNHYTGBVFREDC');
c.log('>> plaintext2 : '+plaintext);
@ccckmit
ccckmit / gist:b1184d2df88578a79c48
Last active August 29, 2015 14:16
helloHtmServer.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<html><head><meta charset="UTF-8"></head><body><a href="http://tw.yahoo.com">yahoo</a> Hello World 你好!</body></html>\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
@ccckmit
ccckmit / gist:d29f59dbed9f22a54568
Last active August 29, 2015 14:17
CPU0 組合語言的祖譯過程
D:\ccc\code\ch12>make
gcc.exe -D__DEBUG__ -c Parser.c -o Parser.o -g3
gcc.exe -D__DEBUG__ -c Tree.c -o Tree.o -g3
gcc.exe -D__DEBUG__ -c Lib.c -o Lib.o -g3
gcc.exe -D__DEBUG__ -c Scanner.c -o Scanner.o -g3
gcc.exe -D__DEBUG__ -c Array.c -o Array.o -g3
gcc.exe -D__DEBUG__ -c Compiler.c -o Compiler.o -g3
gcc.exe -D__DEBUG__ -c HashTable.c -o HashTable.o -g3
gcc.exe -D__DEBUG__ -c Generator.c -o Generator.o -g3
gcc.exe -D__DEBUG__ -c Assembler.c -o Assembler.o -g3
// file df.c
#include <stdio.h>
#include <math.h>
double dx = 0.0001;
double df(double x, double (*f)(double)) {
double dy = (*f)(x+dx)-(*f)(x);
return dy/dx;
}
@ccckmit
ccckmit / function.js
Created September 30, 2016 01:48
test
// 第一種寫法,直接宣告函數
function sub(a,b) {
return a-b;
}
// 第二種寫法,將匿名函數指定給變數。
var add = function(a,b) {
return a+b;
}
console.log("add(3,5)=", add(3,5), " sub(7,2)=", sub(7,2));
@ccckmit
ccckmit / RnnGenerateCode.c
Created May 11, 2018 09:47
RNN 寫出來的程式
/*
* Copyright (c) 2006-2010, Intel Mobile Communications. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#include <pthread.h> // 引用 pthread 函式庫
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
void *print_george(void *argu) { // 每隔一秒鐘印出一次 George 的函數
while (1) {
printf("George\n");
sleep(1);
}
#include <pthread.h> // 引用 pthread 函式庫
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
void *print_george(void *argu) { // 每隔一秒鐘印出一次 George 的函數
while (1) {
printf("George\n");
sleep(1);
}
#include <stdio.h>
#include <pthread.h>
#define LOOPS 100000
int counter = 0;
void *inc()
{
for (int i=0; i<LOOPS; i++) {
counter = counter + 1;
#include <stdio.h>
#include <pthread.h>
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
#define LOOPS 100000
int counter = 0;
void *inc()
{
for (int i=0; i<LOOPS; i++) {