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 / slide-toggle-usage.html
Last active February 19, 2018 04:41
slide-toggle: es6 vanilla javascript with SASS
<button class="js-slide-toggle__btn">toggle</button>
<div class="js-slide-toggle__content">
Nunc nec neque. In turpis. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. In auctor lobortis lacus.
Etiam sit amet orci eget eros faucibus tincidunt. Proin faucibus arcu quis ante. Sed aliquam ultrices mauris. Aenean viverra rhoncus pede. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi.
</div>
@leocaseiro
leocaseiro / commit-msg
Last active August 16, 2019 01:27
Git commit-msg hook to check minimal 10 characters length for git commit message
#!/usr/bin/env bash
# Hook to make sure that no commit message line is lower then 10 characters
while read line; do
# Skip comments
if [ "${line:0:1}" == "#" ]; then
continue
fi
if [ ${#line} -le 10 ]; then
@leocaseiro
leocaseiro / date-format.pipe.ts
Created May 11, 2017 00:10
Angular 4 date-fns Pipe
import { Pipe, PipeTransform } from '@angular/core';
import * as format from 'date-fns/format';
@Pipe({
name: 'dateFnsFormat'
})
export class DateFnsFormatPipe implements PipeTransform {
transform(value, args?) {
return format(value, args);
@leocaseiro
leocaseiro / Batch File Rename with prefix number.scpt
Last active March 3, 2017 23:20 — forked from oliveratgithub/Batch File Rename.scpt
Simple AppleScript to easily batch rename multiple files sequentially. GUI asks user to select files and input a name before renaming.
-- This code is fork from https://gist.github.com/oliveratgithub/
-- Open in AppleScript Editor and save as Application
-- ------------------------------------------------------------
--this is required to break the filename into pieces (separate name and extension)
set text item delimiters to "."
tell application "Finder"
set all_files to every item of (choose file with prompt "Choose the Files you'd like to rename:" with multiple selections allowed) as list
display dialog "New file name:" default answer ""
set new_name to text returned of result
--now we start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file.
@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);
@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 / 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 / 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 / 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 / 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'),