Skip to content

Instantly share code, notes, and snippets.

View saiury92's full-sized avatar
🎯
Focusing

Khánh Thiện saiury92

🎯
Focusing
View GitHub Profile
@saiury92
saiury92 / jwplayer.html
Last active September 14, 2015 09:26 — forked from ph3nx/jwplayer.html
This is how you setup the jwplayer with a self-hosted video file. The official documentation: http://www.longtailvideo.com/support/jw-player/28833/quick-start-guide
<!-- JW Player Library -->
<script src="http://jwpsrv.com/library/MCK8hplLEeOY0CIACmOLpg.js"></script>
<!-- div for the player -->
<div id='playerKXSDPIwKERSv'></div>
<!-- Script to display video file in the player div -->
<script type='text/javascript'>
jwplayer('playerKXSDPIwKERSv').setup({
// URL to the video file
@saiury92
saiury92 / cors.js
Last active September 16, 2015 04:50
Perform cross-origin resource sharing POST request. Hides the use of XDomainRequest for IE from the caller if running in IE. When submitting via IE, the JSON representation of the form data is encoded in Base64 in order to safely send it as a query parameter. The server side needs to implement a Base64 decode strategy in order to get at the form…
/*global webapp, XDomainRequest, Base64*/
webapp.Util = webapp.Util || {};
(function() {
'use strict';
webapp.Util.corsPost = function(url, form, successCallback, errorCallback) {
if (!window.XDomainRequest) {
var deferred = $.ajax({
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@saiury92
saiury92 / provision1404.sh
Created October 28, 2015 04:40 — forked from dakira/provision1604.sh
Basic provisioning for Ubuntu 14.04
#!/bin/bash
apt-get update
apt-get install -y dialog
apt-get -y dist-upgrade
apt-get install -y bash-completion joe-jupp mosh byobu software-properties-common \
php5-fpm php5-gd php5-ldap php5-mysql php5-mcrypt php5-json php5-sqlite \
libapache2-mod-fastcgi \
python-setuptools python-simplejson python-imaging python-mysqldb python-flup \
@saiury92
saiury92 / .gitconfig
Created December 9, 2015 09:20 — forked from RajaJaganathan/.gitconfig
my favorites gitconfig options
[user]
name = Raja J
email = raja_j@apple.com
[alias]
aa = add --all
br = branch
ca = commit --amend
cb = checkout -b
cm = commit -a --amend -C HEAD
ci = commit -a -v
@saiury92
saiury92 / promises.md
Created December 10, 2015 01:40 — forked from bricker/promises.md
Promises in Rails callbacks, using after_save and after_commit together.

"Russian-Doll Caching" is great. It embraces the Rails (and Ruby) goal to "make the developer happy". And it does. Not having to worry about cache expiration is superb.

It has its limits, though. If you're trying to avoid any database queries, russian-doll caching will not work for you. If you are trying to represent thousands, or even hundreds, of objects under a single cache fragment, russian-doll caching is not the best option.

We use it whenever it makes sense, but sometimes we just have to bite the bullet and expire a cache fragment manually. When you want to start manually expiring cache on a fairly busy website, you have to start considering race conditions. I recently ran into the following scenario:

class Post < ActiveRecord::Base
  after_save :expire_cache
  
@saiury92
saiury92 / edge_detection.rb
Created January 11, 2017 08:43 — forked from jrobertson/edge_detection.rb
Edge detection with the Sobel operator in Ruby
require 'chunky_png'
class ChunkyPNG::Image
def at(x,y)
ChunkyPNG::Color.to_grayscale_bytes(self[x,y]).first
end
end
img = ChunkyPNG::Image.from_file('engine.png')
@saiury92
saiury92 / config_server_with_chef_for_rails.md
Created August 25, 2017 08:28 — forked from francois-blanchard/config_server_with_chef_for_rails.md
Build server with chef for deploy rails app

Configure server for deploy rails app

Objective

Prepare a server for a Rails app with MySQL (percona) + NGINX (passenger)
Deploy rails app in new server with Capistrano v3

For this example we need :

-- phpMyAdmin SQL Dump
-- version 4.5.4.1deb2ubuntu2
-- http://www.phpmyadmin.net
--
-- Máy chủ: localhost
-- Thời gian đã tạo: Th10 30, 2017 lúc 01:39 PM
-- Phiên bản máy phục vụ: 5.7.20-0ubuntu0.16.04.1
-- Phiên bản PHP: 7.0.22-0ubuntu0.16.04.1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
import spacy.en
from spacy.symbols import VERB, nsubj, dobj
def find_acquisitions(nlp, text, buy_words):
doc = nlp(text)
for ent in doc.ents:
ent.merge(ent.root.tag_, ent.text, ent.label_)
buy_words = set(nlp.vocab.strings[w] for w in buy_words)
for token in doc:
if token.pos == VERB and token.lemma in buy_words: