Skip to content

Instantly share code, notes, and snippets.

View andrei-cacio's full-sized avatar
👀
🤔 👀

Andrei Cacio andrei-cacio

👀
🤔 👀
View GitHub Profile
@andrei-cacio
andrei-cacio / nginx.conf
Created October 9, 2015 19:24 — forked from Stanback/nginx.conf
Example Nginx configuration for serving pre-rendered HTML from Javascript pages/apps using the Prerender Service (https://github.com/collectiveip/prerender). Instead of using try_files (which can cause unnecessary overhead on busy servers), you could check $uri for specific file extensions and set $prerender appropriately.
server {
listen 80;
listen [::]:80;
server_name yourserver.com;
root /path/to/your/htdocs;
error_page 404 /404.html
index index.html;
@andrei-cacio
andrei-cacio / .bash_profile.sh
Last active May 19, 2016 18:52
pimp-my-bash-console1
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
const fakeDOM = require(‘jsdom’).jsdom(); 
nodeJquery = require(‘jquery’)(fakeDom.defaultView);
import { View } from 'backbone';
import { getJquery }from './jquery-getter';
const $ = getJquery();
export class SimpleView extends View {
constroctor() {
super({ el: '#someDiv' });
}
@andrei-cacio
andrei-cacio / jquery-getter.js
Last active June 12, 2016 09:33
jQuery getter function
let nodeJquery = null;
export function getJquery(spy = false) {
if (!nodeJquery) {
const sinon = require('sinon');
const fakeDOM = require('jsdom').jsdom();
nodeJquery = require('jquery')(fakeDOM.defaultView);
}
return nodeJquery;
import $ from 'jquery';
export const isEmpty = value => !value.length;
export default function getValidator(rule, inputSelector, valueGetter) {
return {
validate() {
const $input = $(inputSelector);
const value = valueGetter();
const sinon = require('sinon');
const fakeDOM = require('jsdom').jsdom();
let nodeJquery = null;
let jquerySpies = null;
export function getJquery() {
if (!nodeJquery) {
nodeJquery = require('jquery')(fakeDOM.defaultView);
}
import { assert } from 'chai';
import proxyquire from 'proxyquire';
import { getJquerySpies, getJquery } from '../src/jquery-getter';
const $ = getJquery();
const getValidator = proxyquire('../src/validator', { jquery : $ }).default;
const isEmpty = proxyquire('../src/validator', { jquery : $ }).isEmpty;
const addClassFn = getJquerySpies().addClass;
@andrei-cacio
andrei-cacio / reducers.js
Last active October 21, 2016 08:49
Redux reducers refactored using ES2015 enhanced object literals
import { combineReducers } from 'redux';
import { LOGIN, LOGOUT } from './action-types';
const initialState = {};
const user = (state = initialState, action) => {
const actionTypeHandlerMap = {
[LOGIN]: ({ status, userInfo }) => ({ ...state, status, userInfo }),
[LOGOUT]: ({ status }) => ({ ...state, status, userInfo: {}}),
[undefined]: () => state
}