Skip to content

Instantly share code, notes, and snippets.

View LostKobrakai's full-sized avatar

Benjamin Milde LostKobrakai

View GitHub Profile
@LostKobrakai
LostKobrakai / navbar_small.sass
Created September 29, 2017 09:56
Small navbar bulma
$navbar-small-height: 2.75rem !default
.navbar.is-small
min-height: $navbar-small-height
& > .container
min-height: $navbar-small-height
.navbar-brand,
.navbar-tabs
@LostKobrakai
LostKobrakai / sliding_session_timeout.ex
Created September 18, 2017 08:22 — forked from qertoip/sliding_session_timeout.ex
Elixir / Phoenix Sliding Session Timeout Plug
# How to use it:
#
# Plug it at the end of your :browser pipeline in your Phoenix app router.ex
# Make sure it is plugged before your session-based authentication and authorization Plugs.
#
# pipeline :browser do
# plug :accepts, ["html"]
# plug :fetch_session
# plug :fetch_flash
# plug :put_secure_browser_headers
defmodule App.RegistrationController do
use App.Web, :controller
alias App.{Registration, Repo}
def new(conn, _params) do
changeset = Registration.changeset(%Registration{})
render conn, :new, changeset: changeset
end
def create(conn, %{"registration" => registration_params}) do
@LostKobrakai
LostKobrakai / date_time_generators.ex
Last active March 17, 2024 17:21
stream_data generators to create elixir date/time structs
defmodule DateTimeGenerators do
use ExUnitProperties
@time_zones ["Etc/UTC"]
def date do
gen all year <- integer(1970..2050),
month <- integer(1..12),
day <- integer(1..31),
match?({:ok, _}, Date.from_erl({year, month, day})) do
@LostKobrakai
LostKobrakai / post.md
Last active April 7, 2020 20:07 — forked from nahtnam/post.md
Using Laravel-Mix with Phoenix

Introduction

Laravel-Mix is "an elegant wrapper around Webpack for the 80% use case". It has nothing to do with Elixir's Mix and does not require Laravel to work!

Set up

Create a new phoenix application with mix phx.new. You may choose to add the --no-brunch flag to stop brunch from being intiailized, but I personally prefer leaving that in and replacing brunch so that the folder structure is set up for me.

$ mix phx.new demo

Install Laravel-Mix

@LostKobrakai
LostKobrakai / factory.ex
Last active June 28, 2017 10:57
Simple Ecto Factory
defmodule MyApp.Factory do
alias MyApp.Repo
# Factories
def build(:name, :default) do
%MyApp.Struct{
}
end
@LostKobrakai
LostKobrakai / 01_usage.exs
Last active June 12, 2017 13:36
Spliting god-object db table into on demand loadable chunks with ecto
# Basic user with just name, email, password
user = Repo.get User, 1
# Load profile
user = Repo.preload(user, :profile)
profile = user.profile
server {
## [Default Nginx Configuration]
# .htaccess 8.1
charset utf-8;
# .htaccess 3.
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
@LostKobrakai
LostKobrakai / WireUploadChunked.php
Created February 16, 2017 09:52
WireUpload subclass to support chunked uploads by http://www.resumablejs.com/
<?php namespace LostKobrakai;
class WireUploadChunked extends \ProcessWire\WireUpload {
/**
* @var bool $uploadingChunkFile
*/
protected $uploadingChunkFile = false;
/**