Skip to content

Instantly share code, notes, and snippets.

View sdelamo's full-sized avatar

Sergio del Amo sdelamo

View GitHub Profile
@sdelamo
sdelamo / Micronaut4M1.md
Last active February 16, 2023 11:39
Micronaut Framework 4 Milestone 1 Blog post
@sdelamo
sdelamo / Updating without calling save explicitly
Created September 7, 2017 16:06
Don't do this, call save when you want to update or save
package demo
class Note {
String msg
}
package demo
import grails.gorm.transactions.ReadOnly
import grails.gorm.transactions.Transactional
@sdelamo
sdelamo / mandrill_remove_tags.groovy
Created November 24, 2015 08:08
A script to remove a list of tags from mandrill
def apiKey = 'yoursecretApiKey'
[
'tagNameA', 'tagNameB'].each { tagName ->
def process = [ 'bash', '-c', "curl -v -k -X POST -H \"Content-Type: application/json\" -d '{\"key\":\"${apiKey}\", \"tag\":\"${tagName}\"}' https://mandrillapp.com/api/1.0/tags/delete.json" ].execute()
process.waitFor()
println process.err.text
println process.text
}
@sdelamo
sdelamo / functions.php
Last active August 29, 2015 14:20
Add Forbidden Mime Types to Wordpress
<?php
function custom_upload_mimes ( $existing_mimes = array() ) {
// add your extension to the array
$existing_mimes['gpx'] = 'application/application/gpx+xml';
$existing_mimes['kml'] = 'application/vnd.google-earth.kml+xml';
// or: $existing_mimes['ppt|pot|pps'] = 'application/vnd.ms-powerpoint';
// to add multiple extensions for the same mime type
// add as many as you like
// removing existing file types
@sdelamo
sdelamo / gist:2c641d09a1d949b1739c
Created May 2, 2015 08:04
Groovy Script to get city name by IP
def cityByIP = { ip, provider, apikey ->
if(provider == "ip-api") {
String urlStr = "http://ip-api.com/json/${ip}?callback=yourfunction"
try {
def data = new URL(urlStr).getText()
int indexOfCity = data.indexOf('city')
indexOfCity += 'city":"'.size()
int indexOfCountry = data.indexOf('country')
indexOfCountry -= '","'.size()
@sdelamo
sdelamo / gist:a6858fdef7b2aa8386be
Created April 8, 2015 08:00
Funciones para obtener el ancho y alto del viewport en javascript
function getViewPortHeight() {
var viewportheight;
if (typeof window.innerWidth != 'undefined') {
viewportheight = window.innerHeight;
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
viewportheight = document.documentElement.clientHeight;
} else {
viewportheight = document.getElementsByTagName('body')[0].clientHeight;
}
@sdelamo
sdelamo / gist:e852efb67a1bb2ed8bf1
Created April 8, 2015 07:53
Change width and height of images and iframe elements which have these attributes set directly. Useful in wordpress theme development for responsive design
$(function () {
$(document).ready(function() {
var padding = 10;
$('img').each(function () {
changeElementWidthAndHeightToFitParentSize($(this),padding);
});
$('iframe').each(function () {
changeElementWidthAndHeightToFitParentSize($(this),padding);
});