Skip to content

Instantly share code, notes, and snippets.

Cheng Fan onlyurei

View GitHub Profile
homerjam / nuxt-axios-cache.js
Last active Aug 21, 2019
Simple plugin which decorates the community axios nuxt-module with an lru-cache
View nuxt-axios-cache.js
import hash from 'object-hash';
import sizeof from 'object-sizeof';
import lruCache from 'lru-cache';
const cacheEnabled = true;
const cacheMaxAge = 30 * 60 * 1000;
const cacheMaxSize = 128 * 1000 * 1000;
const getCacheKey = config => hash({
method: config.method,
yann-yinn / api.js
Created Aug 23, 2017
Using cachios with Nuxt.js and express
View api.js
* Get content from wordpress via REST Api
const config = require('../nuxt.config.js')
const axios = require('axios')
// always call the proxy here :
const endpoint = config.env.proxyApiBaseUrl
* @param {int} perPage : number of post to return per page
myronmarston / without_foreign_keys.rb
Created Sep 6, 2014
Example of how to disable foreign keys for a particular context
View without_foreign_keys.rb
RSpec.shared_context "without foreign key constraints", :disable_foreign_keys do
def without_foreign_key_checks'SET foreign_key_checks = 0;')
ensure'SET foreign_key_checks = 1;')
around(:example) { |ex| without_foreign_key_checks(&ex) }
iros /
Created Aug 22, 2012
Documenting your REST API


<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

piscisaureus /
Created Aug 13, 2012
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url =

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

mikhailov / 0.
Last active Apr 9, 2020
NGINX+SPDY with Unicorn. True Zero-Downtime unless migrations. Best practices.
View 0.
# Nginx+Unicorn best-practices congifuration guide. Heartbleed fixed.
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
# Deployment structure
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
domenic / knockout-es5.js
Created Feb 10, 2012
Speculations on an ES5-style KnockoutJS
View knockout-es5.js
// DESIRED (pending bikeshedding):
// Create using special factory function. Will automatically create `ko.observable`s, `ko.observableArray`s, and
// `ko.computed`s for you, but hide them behind getters/setters.
var viewModel = es5ViewModel({
firstName: "Luke",
lastName: "Skywalker",
fullName: function () {
return this.fullName + this.lastName;
millermedeiros / build.xml
Created Feb 13, 2011
RequireJS optimizer Ant task
View build.xml
<?xml version="1.0" encoding="utf-8"?>
<project name="sample-require-js" default="" basedir=".">
<!-- properties -->
<property name="r.js" value="_build/rjs/r.js" />
<property name="closure.jar" value="_build/closure/compiler.jar" />
<property name="rhino.jar" value="_build/rhino/js.jar" />
<property name="" value="_build/" />
<property name="" value="_build/" />
ryanflorence / static_server.js
Last active Jun 29, 2020
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
View static_server.js
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
You can’t perform that action at this time.