Skip to content

Instantly share code, notes, and snippets.

@JacobHsu
JacobHsu / wget.php
Created November 19, 2014 07:02
#PHP #CI codeingter exe
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once(APPPATH.'libraries/REST_Controller.php');
class Wget extends REST_Controller {
/**
* 影片下載api
* @access public
*/
function index_post()
@JacobHsu
JacobHsu / curl.php
Last active June 8, 2017 14:57
PHP curl POST #PHP
<?php
$fileUrl = 'https://googledrive.com/host/0B8p3dPzRohcndXRaNm1OamFXUUE';
$postArr = array(
"fileurl"=>$fileUrl,"btype"=> '360p,720p',
"recipient"=>'http://php/httpreq/jsonrep.php'
);
$options = array(
CURLOPT_POSTFIELDS => http_build_query($postArr),
@JacobHsu
JacobHsu / postjson.js
Created November 6, 2014 09:05
#nodejs #npm - post json with node.js (npm request )
var request = require('request');
var options = {
uri: 'https://www.googleapis.com/urlshortener/v1/url',
method: 'POST',
json: {
"longUrl": "http://www.google.com/"
}
};
@JacobHsu
JacobHsu / router.js
Created November 3, 2014 08:06
#nodejs async.waterfall callback
require('./waterfallexports')(req.body, function (result) {
console.log('[router] '+result);
});
@JacobHsu
JacobHsu / outvar_fun_name.js
Created November 3, 2014 07:54
#nodejs module.exports VS. exports.function
var url = require("url");
exports.fun = function (postReq, my_callback){
var fileName = url.parse(postReq.fileurl).pathname.split('/').pop();
my_callback('fileName=' + fileName);
}
@JacobHsu
JacobHsu / CashRegister.js
Last active August 29, 2015 14:08
#JS -Building a Cash Register
var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
},
scan: function(item, quantity) {
switch (item) {
case "eggs": this.add(0.98 * quantity); break;
case "milk": this.add(1.23 * quantity); break;
case "magazine": this.add(4.99 * quantity); break;
@JacobHsu
JacobHsu / AddItUp.js
Created November 2, 2014 01:48
#JS Building a Cash Register
var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
}
};
//call the add method for our items
var items = [0.98, 1.23, 4.99, 0.45];
@JacobHsu
JacobHsu / basic.js
Last active August 29, 2015 14:08
#JS What is callbacks?
function basic( callback ){
console.log( '作些事情' );
var result = '我是等會要被傳送給 `do something` 的 callback 的函式結果';
// 如果 callback 存在的話就執行他
callback( result );
}
basic( function( result ){
var redis = require("redis"),
client = redis.createClient();
client.on("error", function (err) {
console.log("Error " + err);
});
client.set("string key", "string val", redis.print); //Reply: OK
client.hset("hash key", "hashtest 1", "some value", redis.print); //Reply: 0
client.hset(["hash key", "hashtest 2", "some other value"], redis.print); //Reply: 0
@JacobHsu
JacobHsu / classAccessingPrivate.js
Created October 30, 2014 00:47
#JS Accessing Private Variables
function Person(first,last,age) {
this.firstname = first;
this.lastname = last;
this.age = age;
var bankBalance = 7500;
this.getBalance = function() {
// your code should return the bankBalance
return bankBalance;
};