Skip to content

Instantly share code, notes, and snippets.

View LinZap's full-sized avatar
🔬
copilot

Zap LinZap

🔬
copilot
View GitHub Profile
@LinZap
LinZap / crawler.php
Created December 18, 2015 09:45
php 5.6.x SSL conn
<?php
$ctx = stream_context_create(['ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]]);
$html = file_get_contents('https://google.com/', FALSE, $ctx);
$meta = stream_context_get_options($ctx)['ssl']['session_meta'];
@LinZap
LinZap / dbconn.R
Created December 25, 2015 07:50
MSSQL and PostgreSQL database connection shortcut
library(RPostgreSQL)
library(RODBC)
pg.conn <- function(set){
conn <- dbConnect(PostgreSQL(), host=set$host, user=set$user, password=set$pwd, dbname=set$dbname)
list(
query = function(sql,params=c()) {
for(i in 1:length(params)){
sql <- gsub( paste("\\$",i,sep="") , paste("'",params[i],"'",sep="") , sql )
}
@LinZap
LinZap / wikipedia_crawler.js
Created January 11, 2016 08:38
wikipedia_crawler for NodeJS
var request = require("request"),
fs = require("fs");
var options = {
url: 'https://zh.wikipedia.org/w/api.php?format=json&action=parse&pageid=13',
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36',
'Cookie' : 'TBLkisOn=0; CP=H2; WMF-Last-Access=11-Jan-2016; GeoIP=:::::v6',
'Accept-Language' : 'zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4'
}
@LinZap
LinZap / tes.php
Created January 13, 2016 00:43
CH_JSON TEST
<?php
try {
$db = new PDO("sqlsrv:server=localhost;Database=rec-booklife","zap","123");
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch( PDOException $e ) {
die( "Error connecting to SQL Server:".$e );
}
$stmt = $db->prepare("select top 100 oid,cname from book");
@LinZap
LinZap / FBI\install.bat
Created January 29, 2016 04:22
The image FBI install on Docker (Windows ver.)
@echo off
echo Load tar...
.\docker.exe load < %1%
echo Run Image...
.\docker.exe run -d -p 9876:80 -p 5433:5432 --name=FBI fbi:v13
pause
@LinZap
LinZap / Progress.php
Created February 17, 2016 13:39
display Progress (PHP ver.)
<?php
class Progress{
private $max;
private $value;
private $length = 10;
private $style = "=";
/*
@LinZap
LinZap / ptt-gossip-patch.sql
Created March 9, 2016 17:40
ptt-gossip sql patch
CREATE INDEX object_title ON object(cname);
CLUSTER object using object_title;
----------------------------------------
CREATE INDEX vd_ptt_post_origin ON vd_ptt_post(origin);
CLUSTER vd_ptt_post using vd_ptt_post_origin;
----------------------------------------
CREATE INDEX vd_ptt_post_oid ON vd_ptt_post(oid);
CLUSTER vd_ptt_post using vd_ptt_post_oid;
----------------------------------------
CREATE INDEX vd_ptt_post_count ON vd_ptt_post(count);
@LinZap
LinZap / node-upgrade.sh
Last active November 9, 2017 20:53
Node.js Upgrade on QNAP
#!/bin/sh
URL=$1
[[ $URL =~ (node-v5\.8\.0-.*)\.tar\.gz$ ]] && TARFile=${BASH_REMATCH[0]} && DirName=${BASH_REMATCH[1]}
[[ $TARFile == "" ]] && echo "url is wrong" && exit
NodeJSPath=$(/sbin/getcfg nodejs Install_Path -f /etc/config/qpkg.conf)
wget --no-check-certificate $URL
@LinZap
LinZap / pla.m
Created March 17, 2016 07:34
PLA
clear
close all
% Generate data
sample_size = 200;
A=repmat([2,2], sample_size,1)+randn(sample_size, 2);
B=repmat([-2,-2],sample_size,1)+randn(sample_size, 2);
X=[A; B];
Y=[ones(sample_size,1); -ones(sample_size,1)];
figure, plot(A(:,1),A(:,2),'ro'), hold on, plot(B(:,1),B(:,2),'xb');
pause;
@LinZap
LinZap / search_engine.sql
Created March 19, 2016 11:15
PTT search_engine
CREATE OR REPLACE FUNCTION search_engine(_words varchar)
RETURNS table (oid int) AS
$BODY$
declare _words_len int;_arrwords varchar[];
begin
select regexp_split_to_array(_words,'[ ,-.~\+]+') into _arrwords;
select array_length(_arrwords,1) into _words_len;
return query
select d.oid from token t,dupindex d,vd_ptt_post p
where t.words in (select unnest(_arrwords))