Skip to content

Instantly share code, notes, and snippets.

@juanmanavarro
juanmanavarro / myEnter.directive.js
Created October 19, 2017 09:26
AngularJS press enter directive
app.directive('myEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.myEnter);
});
event.preventDefault();
}
<?php
function validateNif($nif) {
$nifRegEx = '/^[0-9]{8}[A-Z]$/i';
$nieRegEx = '/^[XYZ][0-9]{7}[A-Z]$/i';
$letras = "TRWAGMYFPDXBNJZSQVHLCKE";
if (preg_match($nifRegEx, $nif)) {
return ($letras[(substr($nif, 0, 8) % 23)] == $nif[8]);
} else {
if (preg_match($nieRegEx, $nif)) {
@juanmanavarro
juanmanavarro / magickdistortimage.c
Last active June 8, 2017 15:24
Use of the MagickDistortImage method from the MagickWand C API
MagickWand *image;
int num_args;
double args[1] = {.5}; // scale the image to half size
double args[1] = {45}; // rotate the image 45 degrees from the center
double args[2] = {.5, 45}; // scale and rotate image
double args[3] = {0, 0, 45}; // rotate the image from 0,0
double args[4] = {0, 0, .5, 45}; // rotate and scale image
double args[6] = {0, 0, .5, 45, 50, 50}; // rotate, scale and translate image to 50,50
@juanmanavarro
juanmanavarro / .htaccess
Created November 10, 2015 15:09
1&1 htaccess file
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]