Skip to content

Instantly share code, notes, and snippets.

@vinhlh
vinhlh / bash_aliases
Last active August 29, 2015 14:20 — forked from frdmn/bash_aliases
alias nginx.start='sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist'
alias nginx.stop='sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.nginx.plist'
alias nginx.restart='nginx.stop && nginx.start'
alias php-fpm.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php54.plist"
alias php-fpm.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php54.plist"
alias php-fpm.restart='php-fpm.stop && php-fpm.start'
alias mysql.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"
alias mysql.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"
alias mysql.restart='mysql.stop && mysql.start'
alias nginx.logs.error='tail -250f /usr/local/etc/nginx/logs/error.log'
@vinhlh
vinhlh / init_pdf.js.sh
Created May 22, 2016 07:26
Setup PDF.js web viewer from its github repository
# configs
JS_DIR=static/js/vendor/pdf.js
CSS_DIR=static/css/vendor/pdf.js
echo "[INFO] Clone https://github.com/mozilla/pdf.js into 'temp'"
git clone -b gh-pages https://github.com/mozilla/pdf.js temp
echo "[INFO] Init pdf.js directories"
rm -rf $JS_DIR
rm -rf $CSS_DIR
@vinhlh
vinhlh / PdfViewer.js
Created May 22, 2016 08:11
React PDF Viewer component using PDF.js (setup the iframe url by https://gist.github.com/vinhlh/22c92f1a9f4fdb72fdbabefee34cef4d)
import React, { Component, PropTypes } from 'react'
import { PDF_VIEWER } from '../configs'
const propTypes = {
ratio : PropTypes.number,
file : PropTypes.string.isRequired
}
const defaultProps = {
ratio: 56.25
@vinhlh
vinhlh / draft.js
Created June 5, 2016 10:58
Convert Draftjs Mentions raw content to HTML
const renderMention = (entity) => {
const { link, name } = entity.data.mention
return `<a href="${link}">${name}</a>`
}
const renderEntity = (entity) => {
if (entity.type === 'mention') {
return renderMention(entity)
}
@vinhlh
vinhlh / CodeBlock.js
Created November 13, 2016 04:56
Minimal React Highlight.js component
import React, { Component, PropTypes } from 'react'
import hljs from 'highlight.js/lib/highlight'
import javascript from 'highlight.js/lib/languages/javascript'
import php from 'highlight.js/lib/languages/php'
import python from 'highlight.js/lib/languages/python'
import sql from 'highlight.js/lib/languages/sql'
import objectivec from 'highlight.js/lib/languages/objectivec'
import 'highlight.js/styles/tomorrow.css'
const propTypes = {
@vinhlh
vinhlh / typeahead.twitter.js
Created November 18, 2016 10:27
Typehead twitter search implement
this.getRemoteSuggestions = function(a, b, c, d) {
if (!b || !this.needsRemoteRequest(b, d))
return;
this.request[a] || (this.attr.useThrottle ?
this.request[a] = utils.throttle(this.splitRemoteRequests.bind(this), this.attr.remoteThrottleInterval) :
this.request[a] = utils.debounce(this.splitRemoteRequests.bind(this), this.attr.remoteDebounceInterval)),
b.query.indexOf("@") === 0 && b.typeaheadSrc === "COMPOSE" && (b.query = b.query.substring(1),
b.atSignRemoved = !0),
this.request[a](a, b, c, d)
}
@vinhlh
vinhlh / typeahead.facebook.js
Created November 18, 2016 10:27
Typehead facebook search implement
m.prototype.throttleSendRemoteQuery = function() {
'use strict';
var n = c('FacebarGlobalOptions').sendRemoteQueryThrottleTime;
if (n === 0) {
this.sendRemoteQueryThrottled = this.sendRemoteQuery;
} else if (c('FacebarGlobalOptions').lazyThrottleRemoteQuery) {
var o = Date.now()
, p = c('FacebarGlobalOptions').enableSendRemoteQueryDelay
, q = c('FacebarGlobalOptions').sendRemoteQueryDelayTime;
this.sendRemoteQueryThrottled = function() {
@vinhlh
vinhlh / debounce.underscore.js
Created November 18, 2016 10:39
debounce.js
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
_.debounce = function(func, wait, immediate) {
var timeout, result;
var later = function(context, args) {
timeout = null;
if (args) result = func.apply(context, args);
@vinhlh
vinhlh / throttle.underscore.js
Created November 18, 2016 10:40
throttle.js
// Returns a function, that, when invoked, will only be triggered at most once
// during a given window of time. Normally, the throttled function will run
// as much as it can, without ever going more than once per `wait` duration;
// but if you'd like to disable the execution on the leading edge, pass
// `{leading: false}`. To disable execution on the trailing edge, ditto.
_.throttle = function(func, wait, options) {
var timeout, context, args, result;
var previous = 0;
if (!options) options = {};
@vinhlh
vinhlh / vl.js
Created November 24, 2016 08:20
alert(1);