Skip to content

Instantly share code, notes, and snippets.

@jmglov
jmglov / config.ex
Created May 18, 2016 11:53
Elixir: override Mix config with environment variables
defmodule Config do
defmacro __using__(_) do
quote do
import unquote(__MODULE__), only: :macros
end
end
defmacro cfg(key, type \\ :string) do
quote do
defp unquote(key)() do
@chadfurman
chadfurman / AcerChromebook11_CB3-111.md
Last active May 2, 2017 14:16
Coffee-Shop Development for Under $500

Coffee-Shop Development for Under $500

Do you have a great desktop, but don't want to shell out premium dollars for a MacBook Pro, only to have security concerns around your beautiful laptop getting stolen? If you feel great when you accomplish something complex, and you want a super-inexpensive backup computer that gives you both freedom and power to develop from your favorite cafe, read on!

In the early days, web development meant local file changes which were sent to the server via FTP. Shelling into the remote server directly was rarely ideal – but technology has come a long way. Chromebooks, starting around $170, have up to 13 hours of battery life and weigh just about 2 lbs. The operating system is designed to run a web browser and nothing else: even your file storage is in the cloud. Enter Cloud9.

Cloud9's web-based IDE is strikingly powerful, feature-rich, and performant on a Chromebook 11. C9 has Goto Anything, rather comprehensive Vim support, and many other power-user accessories. While t

@henrik
henrik / test_helper.exs
Last active June 10, 2020 20:16
Improved `assert_compile_time_raise` based on this comment by Andrea Leopardi: http://andrealeopardi.com/posts/compile-time-work-with-elixir-macros/#comment-2347206739
ExUnit.start()
defmodule CompileTimeAssertions do
defmacro assert_compile_time_raise(expected_exception, expected_message, fun) do
# At compile-time, the fun is in AST form and thus cannot raise.
# At run-time, we will evaluate this AST, and it may raise.
fun_quoted_at_runtime = Macro.escape(fun)
quote do
assert_raise unquote(expected_exception), unquote(expected_message), fn ->
@alexander-yakushev
alexander-yakushev / latex-cheatsheet-template.tex
Last active March 8, 2024 20:50
Beautiful cheatsheet template for key bindings, compiled with XeLaTeX
%% Copyright 2020 Alexander Yakushev
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
@steveklabnik
steveklabnik / summary.md
Created September 29, 2015 14:39
my summary of "using Rust with Ruby: a deep dive with Yehuda Katz"

My summary of https://www.youtube.com/watch?v=IqrwPVtSHZI

TL;DR:

Rails has a library, ActiveSupport, which adds methods to Ruby core classes. One of those methods is String#blank?, which returns a boolean (sometimes I miss this convention in Rust, the ?) if the whole string is whitespace or not. It looks like this: https://github.com/rails/rails/blob/b3eac823006eb6a346f88793aabef28a6d4f928c/activesupport/lib/active_support/core_ext/object/blank.rb#L99-L117

It's pretty slow. So Discourse (which you may know from {users,internals}.rust-lang.org) uses the fast_blank gem, which provides this method via a C implementation instead. It looks like this: https://github.com/SamSaffron/fast_blank/blob/master/ext/fast_blank/fast_blank.c

For fun, Yehuda tried to re-write fast_blank in Rust. Which looks like this:

@stevedomin
stevedomin / create_post.exs
Last active December 26, 2024 09:19
Using UUIDs as primary key with Ecto
defmodule MyBlog.Repo.Migrations.CreatePost do
use Ecto.Migration
def change do
create table(:posts, primary_key: false) do
add :id, :uuid, primary_key: true
add :body, :string
add :word_count, :integer
timestamps
(require 'vlad.core)
(def rules
(join (attr [:name] present)
(attr [:message] present)))
(def names
{[:name] "Name"
[:message] "Message"})
var pureRender = (Component) => {
Object.assign(Component.prototype, {
shouldComponentUpdate (nextProps, nextState) {
return !shallowEqual(this.props, nextProps) ||
!shallowEqual(this.state, nextState);
}
});
};
module.exports = pureRender;
@elado
elado / cequel-database_cleaner.rb
Last active April 8, 2021 08:25
Cequel + DatabaseCleaner and RSpec
# in spec_helper.rb
RSpec.configure do |config|
records = []
config.before :suite do
Cequel::Record.descendants.each do |klass|
klass.after_create {|r| records << r }
end
end