Skip to content

Instantly share code, notes, and snippets.

View jorgepedret's full-sized avatar
😀
Turned on by Open Source

Jorge Pedret jorgepedret

😀
Turned on by Open Source
View GitHub Profile
@jorgepedret
jorgepedret / gist:1016695
Created June 9, 2011 13:07
Gravity Forms Custom Fields
<?php
add_action("gform_field_input", "ih_gform_field_input", 10, 5);
function ih_gform_field_input($input, $field, $value, $lead_id, $form_id){
//wp_debug($field);
if($field["type"] == "vehicleyear"){
//wp_debug($field['choices']);
//$input = 'Aha!';
}
return $input;
}
bind_searchbar: function() {
var cooq = this,
input = $("#search"),
results = [],
results_element = '.live-search-results',
current_element = null,
show_search_help = null,
hide_search_help = null;
@jorgepedret
jorgepedret / gmaps_load.js
Created April 20, 2012 23:01
Loading Google Maps API on demand
// main.js
function loadGoogleMapsApi(){
if(typeof google === "undefined"){
var script = document.createElement("script");
script.src = "https://maps.google.com/maps/api/js?sensor=false&callback=loadGoogleMapsApiReady";
document.getElementsByTagName("head")[0].appendChild(script);
} else {
loadGoogleMapsApiReady();
}
}
@jorgepedret
jorgepedret / .htaccess
Created June 6, 2011 22:12
Htaccess Prevent hotlinking
RewriteEngine On
#Replace ?mysite\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]
@jorgepedret
jorgepedret / _data.json
Created December 10, 2013 19:52
Using Harp as a library
{
"index": {
"title": "Hello World"
}
}
@jorgepedret
jorgepedret / dabblet.css
Created December 2, 2013 19:22 — forked from LeaVerou/dabblet.css
(C)Leanest CSS spinner ever
/**
* (C)Leanest CSS spinner ever
*/
@keyframes spin {
to { transform: rotate(1turn); }
}
.progress {
position: relative;
@jorgepedret
jorgepedret / sitemap.xml.jade
Created October 25, 2013 19:02
Recursive function to create dynamic sitemap of your website in Harp using Jade
- var paths = [], files = []; function recursiveTree(obj) { if (typeof obj == "object" && !obj.length) { for (item in obj) { if (item === "contents") { recursiveTree(obj[item]); } else if (item != "data") { paths.push(item); recursiveTree(obj[item]); paths.splice(paths.length-1, 1); } } } else if (typeof obj == "object") { for (i in obj) { var file = obj[i]; if (/(\.html$)/.test(file)) { paths.push(file); files.push("/" + paths.join("/")); paths.splice(paths.length-1, 1); } } } }; recursiveTree(public);
xml
urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
- for(i in files) {
url
loc= files[i]
priority 0.5
- }
@jorgepedret
jorgepedret / init.js
Created October 18, 2013 18:24
Snippet to extend Backbone's view to avoid the empty wrapping element when rendering
/*
* Helper method to avoid Backbone wrapping empty element
*/
Backbone.View.prototype.replaceElement = function (html) {
if (typeof html === "string") {
html = $(html);
}
this.$el.replaceWith(html);
$(this.el).undelegate();
this.setElement(html);
@jorgepedret
jorgepedret / gist:7034273
Created October 17, 2013 23:44
testing if current.source matches certain strings
/^\/(gallery|catalog|about)/.test(current.source)
@jorgepedret
jorgepedret / blog.jade
Created October 9, 2013 17:07 — forked from dyoder/blog.jade
Harp blog excerpt example
- function excerpt(markup) {
- return markup.split("<!-- more -->")[0]
- }
.blog.summary
ul
each post, slug in public.posts.data
li
h3 #{post.title}
p.byline