Skip to content

Instantly share code, notes, and snippets.

@teamon
teamon / box.ex
Created August 25, 2017 23:09
Define elixir structs with typespec with single line of code
defmodule Box do
defmacro __using__(_env) do
quote do
import Box
end
end
@doc """
Define module with struct and typespec, in single line
@teamon
teamon / Dockerfile
Created August 31, 2018 10:28
elixir + phoenix + node dockerfile
########################################
# 1. Build nodejs frontend
########################################
FROM node:10.9-alpine as build-node
# prepare build dir
RUN mkdir -p /app/assets
WORKDIR /app
# set build ENV
@teamon
teamon / guide.sh
Created July 28, 2011 19:11
Pow + nginx configuration aka give me back my 80 port!
# Install pow
$ curl get.pow.cx | sh
# Install powder
$ gem install powder
# See that firewall is fucked
$ sudo ipfw show
00100 0 0 fwd 127.0.0.1,20559 tcp from any to me dst-port 80 in <- THIS ONE!!!
65535 81005 28684067 allow ip from any to any
defmodule SupportChat do
import Phoenix.Component
alias Phoenix.LiveView.JS
@doc """
Chat bubble at the bottom right corner.
"""
def bubble(assigns) do
~H"""
<div>
<?php
class Form extends Validation {
private $action;
private $method;
private $name;
private $validation;
private $vMessage;
public $request = array();
public $inputs = array();
@teamon
teamon / copy_link.ex
Last active July 19, 2022 10:09
LiveView Storybook
@teamon
teamon / clock.rb
Created October 20, 2012 21:18
clockwork + sidekiq integration
require 'clockwork'
require 'sidekiq'
# load all jobs from app/jobs directory
# no need to load rails env, we only care about classes
# (#perform method is not invoked in this process)
Dir["app/jobs/*"].each {|f| load f }
module Clockwork
every(1.day, 'midnight.job', :at => '00:00'){
@teamon
teamon / Auth.scala
Created April 8, 2012 13:43
Play2.0 with Github OAuth2 example
package controllers
import lib._
import play.api.mvc._
import play.api.libs.json._
object Auth extends Controller {
val GITHUB = new OAuth2[GithubUser](OAuth2Settings(
# config/initializers/instrumentation.rb
# Subscribe to grape request and log with Rails.logger
ActiveSupport::Notifications.subscribe('grape.request') do |name, starts, ends, notification_id, payload|
Rails.logger.info '[API] %s %s (%.3f ms) -> %s %s%s' % [
payload[:request_method],
payload[:request_path],
(ends-starts)*1000,
(payload[:response_status] || "error"),
payload[:x_organization] ? "| X-Org: #{payload[:x_organization]}" : "",
@teamon
teamon / repo.ex
Last active January 15, 2020 11:15
defmodule Recruitee.Repo do
use Ecto.Repo, otp_app: :recruitee
import Ecto.Query
@doc """
Stream query results
Example:
iex> Candidate
...> |> where([c], c.foo > 4)