Skip to content

Instantly share code, notes, and snippets.

View leocaseiro's full-sized avatar
💭
I',m probably studying...

Leo Caseiro leocaseiro

💭
I',m probably studying...
View GitHub Profile
@leocaseiro
leocaseiro / angular-custom-filter.html
Last active August 29, 2015 14:21
Angular Custom Filter
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<title>Angular Custom Filter</title>
</head>
<body>
<div ng-controller="Filter">
<p>{{text | clean:'-':'.jpg'}}</p>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.min.js"></script>
@leocaseiro
leocaseiro / angular-directive.html
Created May 15, 2015 01:27
Angular Create Custom Directive
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<title>Angular Create Directive</title>
</head>
<body>
<div ng-controller="Example">
<button click="click()">click here</button>
<clicker go-click="click()">I am a transcluder</clicker>
</div>
@leocaseiro
leocaseiro / .htaccess
Last active February 23, 2022 03:59
Angular html5Mode apache working in a subdirectory /app using ngRoute
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /app/index.html [NC,L]
</IfModule>
@leocaseiro
leocaseiro / problems.js
Created June 18, 2015 09:18
Frontend Masters - Javascript: The Good Parts by Douglas Crockford
/*
* @link https://frontendmasters.com/courses/javascript-the-good-parts/
Problems 1-5
A sequence of problems will be presented followed by a solution. Each problem builds on the last so if you get a problem wrong, use the solution to begin the next problem. First, a quick quiz: What is x?
3:19:33 - 3:32:25
Problems 6-9
o Problem 6: Write a function that takes a function and an argument, and returns a function that can supply a second argument.
o Problem 7: Without writing any new functions, show three ways to create the inc function.
o Problem 8: Write methodize, a function that converts a binary function to a method.
o Problem 9: Write demethodize, a function that converts a method to a binary function.
@leocaseiro
leocaseiro / gulpfile.js
Last active November 8, 2015 19:52 — forked from rudijs/gulpfile.js
GulpJS Jshint with Notify on Error
var gulp = require('gulp'),
watch = require('gulp-watch'),
// This will keeps pipes working after error event
plumber = require('gulp-plumber'),
// linting
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),
@leocaseiro
leocaseiro / gulpStringToFile.js
Created February 1, 2016 05:03
Create a file within String using Gulp
gulp.task('createFile', function() {
var filename = 'app.js';
var string = "(function() {\n 'use strict';\n angular.module('App', ['ui-route']);\n})();";
return stringToFile(filename, string)
.pipe(gulp.dest('./js'));
});
function stringToFile(filename, string) {
var src = require('stream').Readable({ objectMode: true });
src._read = function () {
@leocaseiro
leocaseiro / debug.js
Created February 16, 2016 05:00
Pretty print to console in NodeJS
function debug() {
if (arguments.length > 1) {
return console.log(arguments[0], JSON.stringify(arguments[1], null, 2));
} else {
return console.log(JSON.stringify(arguments[0], null, 2));
}
}
@leocaseiro
leocaseiro / example.js
Created June 8, 2016 05:50 — forked from dreadjr/example.js
Lodash / Underscore sort object keys. Like _.sortBy(), but on keys instead of values, returning an object, not an array. Defaults to alphanumeric sort.
var obj = {b: 3, c: 2, a: 1};
_.sortKeysBy(obj);
// {a: 1, b: 3, c: 2}
_.sortKeysBy(obj, function (value, key) {
return value;
});
// {a: 1, c: 2, b: 3}
@leocaseiro
leocaseiro / grid.css
Created October 20, 2016 00:10
CSS Float Grid (one size only)
.row,
.row > * {
box-sizing: border-box;
}
.row::after {
content: "";
clear: both;
display: block;
}
.row .col-1 {width: 8.33%;}
@leocaseiro
leocaseiro / colours.js
Last active November 6, 2016 10:50
Javascript parse colours (Hex to RGB and vice versa) as well as luminance(dark or bright)
/**
* Original code from https://github.com/mike-schultz/materialette
*/
function rgbToHex(r, g, b) {
return "#" + ((1 << 24) + (parseInt(r) << 16) + (parseInt(g) << 8) + parseInt(b)).toString(16).slice(1);
}
function hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);