Skip to content

Instantly share code, notes, and snippets.

@CrBoy
CrBoy / jquery.keycode_event.js
Created May 12, 2013 08:30
可以讓 jQuery 綁定鍵盤事件時指定只對特定按鍵作用的小程式。 使用方式: 1. 引入 jQuery 後,引入此 js 檔 2. 在綁定事件時這樣寫: $(this).keypress(13)(handler); 其中 $(this) 可代換成任何 jQuery 物件,handler 則是一般用於事件的 callback function。在此範例中,僅有當按下的按鍵為 enter 時, handler 才會作用。
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 / ip.php
Created November 20, 2013 03:49
<?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 . ')';
#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]);
@CrBoy
CrBoy / tinychat.php
Created November 29, 2014 17:02
整理資料時發現多年前跟 Ijs、雨蒼聽演講的時候為了偷偷聊天而寫的小聊天室....XD
<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']!=""){
@CrBoy
CrBoy / README
Last active August 29, 2015 14:14
Demo of a problem with git
Initial content
Additional content