Skip to content

Instantly share code, notes, and snippets.

View toanalien's full-sized avatar
🎯
Focusing

Thiên Toán toanalien

🎯
Focusing
View GitHub Profile
@toanalien
toanalien / .js
Last active September 20, 2015 14:57
app.get('/auth/callback', function(req,res){
var optAuthorize = {
url: config.url_oauth,
method: 'POST',
form: {
grant_type: 'authorization_code',
code: req.query.code,
client_id: config.client_id,
client_secret: config.client_secret
@toanalien
toanalien / .js
Created September 25, 2015 16:21
var fs = require('fs');
var request = require('request');
var Box = require('./controllers/BoxControllers');
var box = new Box({
access_token: "duPlRu6eWRWJ42sIEb6Mlc2fUdjx4uRL",
refresh_token: "mPZjuJZxqitdfbSWO7TU2IgxmXuZvF4Ge0bB328jCnL3h3SvMQpmobKx93xajUEi"
});
request.post('https://upload.box.com/api/2.0/files/content', {
@toanalien
toanalien / app.js
Last active October 2, 2015 12:46
get panorama google streetview
var getTileData = require('./modules/get-panorama-tiles');
var panorama = require('./modules/get-panorama-by-location');
var getPanoURL = require('./modules/get-pano-url');
var Canvas = require('canvas');
var request = require('request');
var Image = require('canvas').Image;
var express = require('express');
var app = express();
var fs = require('fs');
@toanalien
toanalien / get-pano-url.js
Created October 2, 2015 04:53
Get Panorama Img Google StreetView
module.exports = streetViewUrl;
function streetViewUrl (panoId, opt) {
opt = opt || {};
var x = opt.x || 0;
var y = opt.y || 0;
var zoom = opt.zoom || 0;
// alternative:
// return 'https://cbks2.google.com/cbk?cb_client=maps_sv.tactile&authuser=0&hl=en&panoid=' + id + '&output=tile&zoom=' + zoom + '&x=' + x + '&y=' + y + '&' + Date.now()
return 'https://geo0.ggpht.com/cbk?cb_client=maps_sv.tactile&authuser=0&hl=en&panoid=' + panoId + '&output=tile&x=' + x + '&y=' + y + '&zoom=' + zoom + '&nbt&fover=2';
}
{% for post in site.posts limit:10 %}
<div class="post-preview">
<h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
<div class="post-date">{{ post.date | date: "%B %d, %Y" }}</div>
{% if post.content.size > 2000 %}
{{ post.content | truncatewords: 300 }} <!-- bad! content gives you rendered html and you will truncate in the middle of a node -->
<a href="{{ post.url }}">read more</a>
{% else %}
{{ post.content }}
{% endif %}
{% for post in site.posts limit:10 %}
<div class="post-preview">
<h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
<div class="post-date">{{ post.date | date: "%B %d, %Y" }}</div>
{{ post.content | split:'<!--break-->' | first }}
{% if post.content contains '<!--break-->' %}
<a href="{{ post.url }}">read more</a>
{% endif %}
</div>
<hr>
@toanalien
toanalien / Facebook.php
Created November 15, 2015 10:23
library\XenForo\Helper\Facebook.php
public static function getAccessToken($url, $code)
{
$options = XenForo_Application::get('options');
if (!$options->facebookAppId)
{
return false;
}
try
@toanalien
toanalien / node-and-npm-in-30-seconds.sh
Created December 15, 2015 17:29 — forked from isaacs/node-and-npm-in-30-seconds.sh
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@toanalien
toanalien / app.js
Created January 7, 2016 05:50
demo node event emitter
/*
* app.js
* @toanalien
*/
var Emitter = require('./emitter');
var emtr = new Emitter();
emtr.on('sayhello', function() {
console.log('hello world !');
@toanalien
toanalien / inherits.js
Created January 7, 2016 07:03
Inheriting from Event Emitter
/*
* inherits.js
* @toanalien
*/
var util = require('util');
var EventEmitter = require('events');
function Toanalien() {
this.toanalien = "Hello !";