Skip to content

Instantly share code, notes, and snippets.

CrBoy

Block or report user

Report or block CrBoy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@CrBoy
CrBoy / README
Last active Aug 29, 2015
Demo of a problem with git
View README
Initial content
Additional content
@CrBoy
CrBoy / tinychat.php
Created Nov 29, 2014
整理資料時發現多年前跟 Ijs、雨蒼聽演講的時候為了偷偷聊天而寫的小聊天室....XD
View tinychat.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TinyChat 簡易的網路聊天室</title>
</head>
<body onload="document.tinychat.say.focus()">
<?
$_GET['nick'] = escapeshellcmd($_GET['nick']);
$_GET['say'] = escapeshellcmd($_GET['say']);
if($_GET['say']!=""){
View rock_1.c
#include <stdio.h>
#include <string.h>
void f1(const char *filename);
int main(int argc, const char *argv[])
{
if(argc<2) return 0;
f1(argv[1]);
View ip.php
<?php
$keys = ['REMOTE_ADDR', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR'];
foreach ($keys as $key) {
$ip = $_SERVER[$key];
echo $key . ' = ' . $ip;
if ($ip != ''){
$location = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));
if($location){
echo ' (' . $location->geoplugin_city . ', ' . $location->geoplugin_countryName . ')';
@CrBoy
CrBoy / jquery.keycode_event.js
Created May 12, 2013
可以讓 jQuery 綁定鍵盤事件時指定只對特定按鍵作用的小程式。 使用方式: 1. 引入 jQuery 後,引入此 js 檔 2. 在綁定事件時這樣寫: $(this).keypress(13)(handler); 其中 $(this) 可代換成任何 jQuery 物件,handler 則是一般用於事件的 callback function。在此範例中,僅有當按下的按鍵為 enter 時, handler 才會作用。
View jquery.keycode_event.js
var extend_keyboard_event_with_keycode = function(original_event_name) {
var $fn_original = $.fn[original_event_name];
var keyboard_event_function_wrapper = function(keycodes, handler) {
return function(e) {
if(keycodes.indexOf(e.which) != -1)
return handler(e);
}
}
@CrBoy
CrBoy / xor.py
Created Apr 26, 2013
簡單的 xor 程式
View xor.py
#!/usr/bin/python
import sys
infile = sys.argv[1]
outfile = sys.argv[2]
key = bytearray(sys.argv[3].decode('hex'))
b = bytearray(open(infile, 'rb').read())
i = 0
@CrBoy
CrBoy / set_with_custom_class.cpp
Created Aug 12, 2012
Example of using set with custom class
View set_with_custom_class.cpp
#include <iostream>
#include <set>
using namespace std;
class MyClass{
public:
MyClass (int _x, int _y):x(_x),y(_y){}
bool operator<(const MyClass& rhs) const {
return this->x < rhs.x ? true : (this->y < rhs.y ? true : false);
@CrBoy
CrBoy / README
Created Jul 18, 2012
範例:使用 PHPMailer 透過 Gmail 寄送信件
View README
本範例使用 PHPMailer (http://sourceforge.net/projects/phpmailer/) 發送 email。
首先需要注意的是,下載時有可能讓人困惑,我下載的是 http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/PHPMailer%20v5.1/ 這個版本。
執行方式:使用 command line php 直接執行 `$ php ezgmail.php`
範例中包含設定方式、訊息樣板 (msg)、簡單樣板引擎 (fill_template)、名單的 parser (parse_name_list_tsv)與自動根據名單發信的範例,皆相當容易修改。
需注意的是,Gmail 有發送郵件相關的限制,若超過限制,帳號會被暫時停用一天。
@CrBoy
CrBoy / magic_call.php
Created Jun 27, 2012
PHP magic function __call example
View magic_call.php
<?php
class MyClass
{
public function __construct()
{
}
public function __call($name, $args)
{
echo "You called method \"$name\", and the args is:\n";
@CrBoy
CrBoy / prime.py
Created Jun 23, 2012
Generate prime numbers example
View prime.py
num = range(100)
result = set(num)
for i in range(2,10):
result -= set(num[i*2::i])
result -= set([0,1])
print result
You can’t perform that action at this time.