Skip to content

Instantly share code, notes, and snippets.

View adamgavlak's full-sized avatar

Adam Gavlák adamgavlak

View GitHub Profile
@adamgavlak
adamgavlak / CacheOrRetrieve.php
Created December 14, 2015 21:45
Laravel middleware for caching routes
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Cache;
class CacheOrRetrieve
{
private $cacheTime = 10;
@adamgavlak
adamgavlak / generate.rb
Created May 27, 2016 08:58
Generate slug
# Generates slug with n characters that matches /[A-Za-z0-9]+/
def generate_slug(n = 7)
[*('A'..'Z'), *('a'..'z'), *('0'..'9')].shuffle[0,n].join
end
@adamgavlak
adamgavlak / app.js
Last active June 30, 2016 17:22
Filter input using attribute
// Takes argument and makes sure that filtered object has attribute with that name set to true
app.filter('attribute', function() {
return function(input, argument) {
var output = [];
if (argument == '') {
return input;
}
for (i in input) {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
document.querySelector(".bold").addEventListener('click', addBold, false);
ta = document.querySelector("textarea[name='content']");
function addBold() {
surroundInTextarea(ta, '**');
return false;
}
function typeInTextarea(el, newText) {
@adamgavlak
adamgavlak / offset_scroll.js
Last active August 28, 2016 10:26
Smooth scrolling to anchor with offset for navigation
var offset = 60;
$("a[href*=#]:not([href=#])").click(function() {
if (location.pathname.replace(/^\//, "") == this.pathname.replace(/^\//, "") || location.hostname == this.hostname) {
var t = $(this.hash);
if (t = t.length ? t : $("[name=" + this.hash.slice(1) + "]"), t.length)
return $("html,body").animate( {scrollTop: t.offset().top - offset}, 1e3), !1
}
});
@adamgavlak
adamgavlak / reveal.js
Created August 28, 2016 10:25
Simple script for revealing password
let password_field = document.querySelector("#user_password")
let password_revealer = document.querySelector("#user_password_revealer")
password_revealer.addEventListener("click", function(e) {
if (password_revealer.checked) {
password_field.type = "text"
} else {
password_field.type = "password"
}
})
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" Plugins
Plugin 'VundleVim/Vundle.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'elixir-lang/vim-elixir'
@adamgavlak
adamgavlak / stack.c
Last active October 4, 2018 16:52
Simple dynamic stack implementation in C
//
// stack.c
//
// Created by Adam Gavlák on 26/09/16.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
div
padding: 10px
@include for-size(desktop-up)
padding: 20px