Skip to content

Instantly share code, notes, and snippets.

@Frost
Frost / google_books.ex
Created May 8, 2015 19:58
Fetching book info from Google Books API using elixir
defmodule GoogleBooks do
use HTTPoison.Base
@base_url "https://www.googleapis.com/books/v1/volumes?q=isbn:"
def process_url(isbn13) do
isbn = String.replace(isbn13, "-", "")
@base_url <> isbn
end
@Frost
Frost / gist:2a902807472d02d7a392
Created March 9, 2015 20:03
Cowsay from PostgreSQL!
First off, install cowsay, and some PostgreSQL language extension, like [plsh](https://github.com/petere/plsh).
Now, make sure to install the language extension in your database:
$ psql
= CREATE EXTENSION plsh;
Now what you need is a function that takes some input and prints it using cowsay:
=# CREATE FUNCTION cowsay (input text) RETURNS text
@Frost
Frost / index.md
Last active April 6, 2024 09:10
Calling `eh` from vim

Calling eh from vim

I use vim, and I occasionally write Elixir code.

Vim has built-in support for looking up documentation, keywordprg.

So since I wanted to be able to look up Elixir documentation from vim, I wrote an elixir package called eh, which is available on hex.

To call eh from vim, add the following to your .vimrc:

@Frost
Frost / leading-dot-behavior.md
Last active August 29, 2015 14:07
coffeescript leading dots behavior change between minor versions

Take this snippet, borrowed from the coffeescript changelog:

$ 'body'
.click (e) ->
  $ '.box'
  .fadeIn 'fast'
  .addClass '.active'
.css 'background', 'white'
@Frost
Frost / index.md
Last active August 29, 2015 14:06
JavaScript vs CoffeeScript vs LiveScript - Type-related arithmetic gotchas
expression JavaScript CoffeeScript LiveScript
1 + 2 3 3 3
1 + "2" '12' '12' '12'
"2" + 1 '21' '21' '21'
1 * 2 2 2 2
"1" * 2 2 2 '11'
1 * "2" 2 2 ''
1 / 2 0.5 0.5 0.5
"1" / 2 0.5 0.5 0.5
@Frost
Frost / ObjectWithDefaultValue.js
Created July 30, 2014 18:04
ECMAScript 6 Proxy Object with default property value
module.exports = exports = ObjectWithDefaultProperty;
function ObjectWithDefaultProperty(properties, defaultValue) {
return Proxy.create({
get: function get(proxy, name) {
if (name in properties) {
return properties[name];
} else {
return defaultValue;
}
}
@Frost
Frost / list-files-with-date-in-filename-older-than-5-days.sh
Created July 3, 2014 15:12
List files with date in filename that is older than 5 days
#!/usr/bin/env bash
# only move files older than 5 days
maxdate=$( date +%Y-%m-%d -d '5 days ago')
# set source and destination folders unless set by env
[ -z "$LOG_SOURCE" ] && LOG_SOURCE="/source/path"
for file in $LOG_SOURCE/*.log.*; do
# example:
@Frost
Frost / livescript-scope-assignment.ls
Created May 15, 2014 13:57
Livescript scope assignment gotcha
foo = {foo: \foo}
bar = ->
console.log foo
foo ?= {bar: \bar}
return foo

Express.js nested apps and routing

So... Say we are building this API in express.js, and it's supposed to have these routes:

/v1
   /ping
   /foo
       /bar
       /baz
@Frost
Frost / hash_default_values.rb
Created January 8, 2014 10:06
Default values for hashes in ruby
# So... hash.new takes an optional parameter with a default value, that's neat.
> hash = Hash.new(0)
> hash["foo"]
=> 0
> hash["bar"] += 5
=> 5
> hash
=> {"bar" => 5}