Skip to content

Instantly share code, notes, and snippets.

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

Juan Cristobal Pazos jCrip

🏠
Working from home
  • Modyo
  • Santiago, Chile
View GitHub Profile
@jCrip
jCrip / preload_images.js
Created November 13, 2013 15:45
Javascript Images Preload
function preload() {
var images = [];
var i;
for ( i = 0; i < preload.arguments.length; i++ ) {
images[ i ] = new Image();
images[ i ].src = preload.arguments[ i ];
}
}
preload(
@jCrip
jCrip / scrollStopped.js
Created November 22, 2013 22:40
scrollStopped event
$.fn.scrollStopped = function(callback) {
$(this).scroll(function(){
var self = this, $this = $(self);
if ($this.data('scrollTimeout')) {
clearTimeout($this.data('scrollTimeout'));
}
$this.data('scrollTimeout', setTimeout(callback,300,self));
});
};
@jCrip
jCrip / getparam.js
Created December 26, 2013 18:18 — forked from varemenos/getparam.js
// Given a query string "?to=email&why=because&first=John&Last=smith"
// getUrlVar("to") will return "email"
// getUrlVar("last") will return "smith"
// Slightly more concise and improved version based on http://www.jquery4u.com/snippets/url-parameters-jquery/
function getUrlVar(key){
var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
return result && unescape(result[1]) || "";
}
@jCrip
jCrip / custom_add_to_cart.html
Last active August 29, 2015 14:01 — forked from juque/custom_add_to_cart.html
Bootic custom_add_to_cart
<!-- Formulario y botón "agregar al carro" en plantilla product.html.
Los data-attributes son necesarios para la API Ajax del carrito (opcional) -->
<form class="add_to_cart" action="{{ add_to_cart_url }}" method="post" data-bootic-cart-add="add" data-bootic-productId="{{ product.id }}">
<!-- si hay más de 1 variante, muéstralas en una lista -->
{% if product.variants_count > 1 %}
<h4>{{ 'activerecord.models.variant' | t }}</h4>
<ul class="variants">
<!-- primero las variantes disponibles -->
{% for variant in product.available_variants %}
<li class="bootic_variant available {% cycle 'odd', 'even' %} av-variant-{{ forloop.index }}">
@jCrip
jCrip / basic_usage.php
Last active August 29, 2015 14:06 — forked from BaylorRae/basic_usage.php
Cycle function like the one in liquid or twig
<?php for( $i = 0; $i < 9; $i++ ) : ?>
<p><?php echo cycle('one', 'two', 'three') ?></p>
<?php endfor; ?>
@jCrip
jCrip / box-sizing.css
Last active August 29, 2015 14:13
Apply a natural box layout model to all elements, but allowing components to change
/* apply a natural box layout model to all elements, but allowing components to change */
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
@jCrip
jCrip / application_helper.rb
Created February 15, 2015 22:08
Rails 4 flash messages using Twitter Bootstrap(bootstrap-sass: https://github.com/thomas-mcdonald/bootstrap-sass).
module ApplicationHelper
def bootstrap_class_for flash_type
{ success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type.to_sym] || flash_type.to_s
end
def flash_messages(opts = {})
flash.each do |msg_type, message|
concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} alert-dismissible", role: 'alert') do
concat(content_tag(:button, class: 'close', data: { dismiss: 'alert' }) do
@jCrip
jCrip / api.rb
Last active August 29, 2015 14:17
# This one goes to the API file.
before do
next if @resource
@req = ::AuthenticatedRequest.new(
uid: request.headers['Uid'],
token: request.headers['Access-Token'],
client: request.headers['Client'],
resource: @resource
)
@jCrip
jCrip / jquery_fallback.html
Created April 17, 2015 00:11
jQuery request with fallback
<!-- jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/assets/js/vendor/jquery-1.11.1.min.js"><\/script>')</script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
echo "* Updating system"
apt-get update
apt-get -y upgrade
echo "* Installing packages"
apt-get -y install build-essential libmagickcore-dev imagemagick libmagickwand-dev libxml2-dev libxslt1-dev git-core nginx redis-server curl nodejs htop
id -u deploy &> /dev/null
if [ $? -ne 0 ]
then