Skip to content

Instantly share code, notes, and snippets.

View kamiyam's full-sized avatar
🏠
Working from home

kamiyam kamiyam

🏠
Working from home
View GitHub Profile
@kamiyam
kamiyam / Singleton.coffee
Last active January 2, 2016 16:49
Always the only instance
do(w=window,d=document) ->
# log output
log = ->
if (typeof console isnt 'undefined')
console.log.apply(console, arguments);
## implements
class Singleton
constructor: ( name ) ->
@kamiyam
kamiyam / app.coffee
Last active January 1, 2016 12:19
socket.io mluti connecting room for sails.js
do ( d=document, w=window, $=jQuery ) ->
# ref http://qiita.com/Layzie/items/465e715dae14e2f601de
_is = (type, obj) ->
clas = Object.prototype.toString.call(obj).slice(8, -1)
return obj isnt undefined && obj isnt null && clas is type
# log output
log = ->
if (typeof console isnt 'undefined')
@kamiyam
kamiyam / main.coffee
Last active January 1, 2016 09:09
main.coffee for jquery.pjax.js (https://github.com/falsandtru/jquery.pjax.js)
do ( d = document, w = window, $ = jQuery ) ->
# Simple log function to keep the example simple
log = ->
console.log.apply console, arguments if typeof console isnt "undefined"
$ ->
viewArea = "#contents"
$.pjax
area: viewArea
@kamiyam
kamiyam / index.ejs
Last active December 29, 2015 01:49
ejs-locals と blocks.xxx を使った URLごとのスクリプトローディング
<div>
<!-- this block is main content area -->
</div>
<%
var fotter_script = (function () {/*
<script>
(function(d,w,$){
@kamiyam
kamiyam / app.js
Created November 22, 2013 01:42
"stylus" & "nib" use auto compiler for Express
var express = require('express');
var path = require('path');
var stylus = require("stylus"), nib = require("nib");
var app = express();
// app.use ...
app.use(stylus.middleware({
src: path.join(__dirname, 'public'),
compile: function (str, path){ return stylus(str).set("filename", path).set("compress", true).use(nib()); }
@kamiyam
kamiyam / server.js
Last active December 28, 2015 09:39
When access WordPress default permalink, 301 redirect to Ghost
//for wordpress permalink import articles
function redirect301 ( req, res, next ){
// console.log("access to: " + req.headers.host);
if ( req.query["p"] || req.query["page"] ){
var redirect = "http://" + req.headers.host;
if ( req.query["p"] ){
redirect += "/p" + req.query["p"] + "";
} else if( req.query["page"] ){
redirect += "/page" + req.query["page"] + "";
@kamiyam
kamiyam / Gruntfile.coffee
Created November 2, 2013 16:56
Sails 0.9.7 default Gruntfile
###
Gruntfile
If you created your Sails app with `sails new foo --linker`,
the following files will be automatically injected (in order)
into the EJS and HTML files in your `views` and `assets` folders.
At the top part of this file, you'll find a few of the most commonly
configured options, but Sails' integration with Grunt is also fully
customizable. If you'd like to work with your assets differently
@kamiyam
kamiyam / Vagrantfile
Last active December 25, 2015 20:39
Vagrant common filesets Using vagrant-omnibus ( if use vagrant-berkshelf, mod Vagrantfile )
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
vagrant = JSON.parse(File.read("./vagrant.json"))
@kamiyam
kamiyam / Sails-ConfigManager.js
Last active December 23, 2015 05:49
sails service & config require manager
module.exports = function() {
var sails = global["sails"];
if ( sails ){
return sails.config;
}
else {
var app = require("../config/application");
try {
var local = require("../config/local");
var _ = require('underscore');
@kamiyam
kamiyam / install.sh
Created September 16, 2013 04:52
npm scripts preinstall Example...
#!/bin/sh
npm i -g grunt-cli
npm i -g forever