Skip to content

Instantly share code, notes, and snippets.

@ktec
ktec / README.md
Created February 19, 2019 22:02
Elixir Test Runner - Test Driven Development with Entr
@ktec
ktec / README
Last active May 16, 2018 01:33
Script to control keyboard led lights for Macbook Pro on Arch Linux
Controlling the keyboard led lights on a Macbook Pro running linux is harder than it should be.
For ...reasons the bundled `kbdlight` doesn't work, so we're left with no option but to roll
up our sleaves and get our hands dirty. Fortunately various bash commands and `bc` makes this
task pretty trivial so here is a script to control the brightness.
This script supports the following api:
$ kbdlight -set 10
$ kbdlight -set +10
@ktec
ktec / README
Last active August 21, 2021 05:00
Script to control the screen brightness (Backlight) for Linux
Controlling the screen brightness on a Macbook Pro running linux is harder than it should be.
For ...reasons the bundled `xbacklight` doesn't work, so we're left with no option but to roll
up our sleaves and get our hands dirty. Fortunately various bash commands and `bc` makes this
task pretty trivial so here is a script to control the brightness.
This script supports the following api:
$ brightness -set 10
$ brightness -set +10
@ktec
ktec / App.js
Last active March 29, 2019 01:15
HOW TO USE PHOENIX WITH WEBPACK + REACT + REDUX - This is a collection of small changes related to: https://www.dailydrip.com/blog/how-to-use-phoenix-with-webpack-react-redux.html
import React, { Component } from "react";
import { connect } from "react-redux";
import MessageList from "../components/MessageList";
import MessageInput from "../components/MessageInput";
import Actions from "../actions";
function App(props) {
const { messages, sendMessage } = props;
return (
@ktec
ktec / application.ex
Last active January 15, 2022 23:46
Example MasterProxy for Elixir Umbrella applications supporting websockets
defmodule MasterProxy.Application do
@moduledoc """
Custom Cowboy specification to support hosting multiple Phoenix apps within the same umbrella,
all served via the same port. This is only really necessary if you're deploying your umbrella
to a restricted hosting environment like Heroku where they only expose 1 port per dyno.
Don't for get to configure your endpoints, something like this should work:
config :myapp_web, MyAppWeb.Endpoint,
url: [scheme: "https", host: "myapp.herokuapp.com", port: 443],
defmodule PyramidCalculator do
@doc """
iex> PyramidCalculator.pyramid_prices_percents([1, 2, 3], 10)
[10.0, 33.33333333333333, 56.666666666666664]
iex> PyramidCalculator.pyramid_prices_percents([1, 2, 3], 40)
[40.0, 33.333333333333336, 26.666666666666668]
iex> PyramidCalculator.pyramid_prices_percents([1, 3, 7, 22], 5)
[5.0, 10.517241379310345, 21.551724137931036, 62.93103448275862]
"""
@ktec
ktec / sumFolds.js
Last active January 30, 2017 22:38
// const Box = x =>
// ({
// map: f => Box(f(x)),
// fold: f => f(x),
// inspect: () => `Box(${x})`
// })
const fmap = f => xs => xs.map(x => f(x))
@ktec
ktec / ssl_puma.sh
Created January 17, 2017 13:43 — forked from tadast/ssl_puma.sh
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
#!/usr/bin/env bash
# Original Source: http://blog.nonuby.com/blog/2012/07/05/copying-env-vars-from-one-heroku-app-to-another/
## Usage: heroku_env_copy [options] SOURCE TARGET
##
## NOTE: This script will only output the command, you should run it yourself.
##
## Options:
## -h, --help Display this message.
##
@ktec
ktec / arel_cast_datetime_as_as.rb
Last active June 27, 2016 14:39
When you want to filter by date, but you've only got a datetime property, this will help you cast your datetime
# frozen_string_literal: true
class Things < ApplicationRecord
scope :filter_after_date, -> (date) {
where(created_at_as_date.gteq(date))
}
scope :filter_before_date, -> (date) {
where(created_at_as_date.lteq(date))
}
def self.created_at_as_date
Arel::Nodes::NamedFunction.new "DATE", [ arel_table[:created_at] ]