Skip to content

Instantly share code, notes, and snippets.

@JacobHsu
JacobHsu / search_app_add.php
Created April 7, 2016 00:54
#Elasticsearch #patch #PHP
<?php
/*
* search app 建立資料
* 說明:
*
* 執行 `patch/search_app_add.php`
* php patch/search_app_add.php
*
* 清除
* php search_app_add.php clear
@JacobHsu
JacobHsu / pagination.js
Last active February 25, 2023 00:27
PaginationHelper class #js
// TODO: complete this object/class
// http://www.codewars.com/kata/515bb423de843ea99400000a/train/javascript
// The constructor takes in an array of items and a integer indicating how many
// items fit within a single page
function PaginationHelper(collection, itemsPerPage){
this.items = collection;
this.itemsPerPage = itemsPerPage;
}
@JacobHsu
JacobHsu / phantomjs_facebook.js
Created January 7, 2016 05:31
Log into Facebook with phantomJS
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open("https://www.facebook.com", function(status) {
if ( status === "success" ) {
page.evaluate(function() {
@JacobHsu
JacobHsu / phantomjs_facebook.js
Created January 7, 2016 05:20
Log into Facebook with phantomJS
var page = require('webpage').create();
var fillLoginInfo = function(){
var frm = document.getElementById("login_form");
frm.elements["email"].value = 'your fb email/username';
frm.elements["pass"].value = 'password';
frm.submit();
}
page.onLoadFinished = function(){
@JacobHsu
JacobHsu / clientWidthHeight.html
Last active November 19, 2015 14:25
瀏覽器窗口可視區域大小 在不同瀏覽器都適用的 JavaScript 方案
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript">
var w= document.documentElement.clientWidth || document.body.clientWidth;
var h= document.documentElement.clientHeight || document.body.clientHeight;
document.write("Width:"+w+"<br>"+"Height:"+h)
<?php
$number = 2;
$str = "Shanghai";
$txt = sprintf("There are %u million cars in %s.",$number,$str);
echo $txt;
?>
@JacobHsu
JacobHsu / vehicle.ls
Created January 21, 2015 13:12
#JS Object
var vehicle1 = {type: "Motorboat", capacity: 6, storedAt: "Ammunition Depot"};
var vehicle2 = {type: "Jet Ski", capacity: 1, storedAt: "Reef Dock"};
var vehicle3 = {type: "Submarine", capacity: 8, storedAt: "Underwater Outpost"};
var vehicles = [vehicle1, vehicle2, vehicle3];
var findVehicle = function (name, list){
for(var i = 0; i<list.length; i++){
if(list[i].type == name){
return list[i].storedAt;
}
<style id="jsbin-css">
.spinner {
margin: 100px auto;
width: 20px;
height: 20px;
position: relative;
}
.container1 > div, .container2 > div, .container3 > div {
width: 6px;
pollingLoop();
function pollingLoop(){
var cp = require('child_process');
var child = cp.fork('./worker');
var num = Math.floor((Math.random() * 100) + 1);
child.on('message', function(m) {
@JacobHsu
JacobHsu / index.html
Created November 23, 2014 03:03
Interactive Website: Push Menu // source http://jsbin.com/fuzekotepi
<html>
<head>
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400;300' rel='stylesheet' type='text/css'>
<link href='style.css' rel='stylesheet'>
<style id="jsbin-css">
/* Initial body */
body {
left: 0;