Skip to content

Instantly share code, notes, and snippets.

View nczz's full-sized avatar
🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。

一介資男 nczz

🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。
View GitHub Profile
jQuery('a').click(function(e){
var url = jQuery(this).attr('href');
if (!/^([javascript]|[mailto])/.test(url)){
e.preventDefault();
location=url+location.search+location.hash;
}
});
@nczz
nczz / WriteForLittlePig.js
Created September 11, 2015 07:38
WriteForLittlePig
//1~4
for (var i=1; i<5; ++i){
$('#menu_'+i).click(function(){
$('#tab_'+$(this).attr('id').split('_')[1]).trigger('click');
});
}
@nczz
nczz / jQueryGoogleAnalyticsPageTrackingPlug-in.js
Created September 19, 2015 15:55
jQuery Google Analytics Page Tracking Plug-in
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'YOUR-GA-CODE', 'auto');
ga('require', 'displayfeatures');
ga('send', 'pageview');
$(document).ready(function() {
page_id = $('body').attr('data-tracking-id');
page_type = $('body').attr('data-tracking-type');
ga('send', 'event', 'page', page_id, 'total-view');
@nczz
nczz / Power of Thor.js
Created October 11, 2015 13:21
codingame.com -> Power of Thor JavaScript solution
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
* ---
* Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
**/
var inputs = readline().split(' ');
var lightX = parseInt(inputs[0]); // the X position of the light of power
var lightY = parseInt(inputs[1]); // the Y position of the light of power
#include <stdio.h>
#include <sys/types.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <string.h>
#include <arpa/inet.h>
int main (int argc, const char * argv[]) {
struct ifaddrs * ifAddrStruct=NULL;
struct ifaddrs * ifa=NULL;
@nczz
nczz / update_ip.sh
Last active October 27, 2015 06:18
Update dynamic IP to server
#!/bin/bash
ip=`ip -4 route get 1 | head -1 | cut -d' ' -f8 | tr -d '\n'`
now=`date`
printf -v data '{"IP":"%s","UpdatedAt":"%s"}' $ip "$now"
curl -X PATCH -d "$data" 'http://path.to/server/log'
@nczz
nczz / CCAttackPrevention.php
Last active October 31, 2015 14:01
PHP - CC Attack Prevention
<?php
$reqMethod = getenv('REQUEST_METHOD');
$reqIP = filter_var(getenv('HTTP_CLIENT_IP'), FILTER_VALIDATE_IP) ? getenv('HTTP_CLIENT_IP') : (filter_var(getenv('HTTP_X_FORWARDED_FOR'), FILTER_VALIDATE_IP) ? getenv('HTTP_X_FORWARDED_FOR') : getenv('REMOTE_ADDR'));
$salt = "Only_U_Know_Me: {$reqIP} in ".round(time() / 604800, 0);
$clientKey = md5($salt);
$expires = gmdate("l, d-M-Y H:i:s T", time() + 604800); // 7 days
if (strtoupper($reqMethod) == 'POST' /*&& EXCLUDE API URL REQUEST*/) {
if (!isset($_COOKIE[$clientKey])){
exit();
@nczz
nczz / sms_sample.php
Created January 26, 2016 10:26
簡訊王 API 範例
<?php
function sms_api($username,$password,$dest_addr,$text_str){
$api_host = 'http://202.39.48.216/kotsmsapi-1.php';
if ( $text_str=='' || !preg_match("/^[0-9]{10}$/", $dest_addr) || $username=='' || $password=='' ){
return 'ERROR Params.';
}
$data = array(
'username'=>$username,
'password'=>$password,
'dstaddr'=>$dest_addr,
@nczz
nczz / install.sh
Created March 12, 2016 09:07
Git AutoComplete Script
#!/bin/bash
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
chmod +x ~/.git-completion.bash
. ~/.git-completion.bash
echo 'if [ -f ~/.git-completion.bash ]; then' >> ~/.bash_profile
echo ' . ~/.git-completion.bash' >> ~/.bash_profile
echo 'fi' >> ~/.bash_profile
@nczz
nczz / functions.php
Last active August 27, 2023 15:39
開啟一個WordPress專案時的初始化項目(此處已不再維護,請移駕 https://github.com/nczz/work_with_wordpress 這專案查看最新更動)
<?php
//修正管理後台頁尾顯示
function dashboard_footer_design() {
echo 'Design by <a href="https://www.mxp.tw">Mxp</a>';
}
add_filter('admin_footer_text', 'dashboard_footer_design');
//修正管理後台頁尾顯示
function dashboard_footer_developer() {
echo '<br/><span id="footer-thankyou">Developed by <a href="http://www.mxp.tw">Mxp</a></span>';