Skip to content

Instantly share code, notes, and snippets.

View tdantas's full-sized avatar
🏠
Working from home

Thiago Dantas tdantas

🏠
Working from home
View GitHub Profile
@tdantas
tdantas / model.js
Created April 30, 2014 06:56
mongoose test post middleware
var Page = new Schema({
title: { type: String, default: '', trim: true },
url: { type: String, default: '', trim: true },
thumbnails: {type: Schema.ObjectId, ref: 'Thumbnails'},
});
Page.post('save', function(doc) {
if(doc.thumbnails) return;
Thumbnail.generate(doc.url, function(err, thumb){
doc.thumbnails = thumb;
@tdantas
tdantas / fizzbuzz.ex
Last active August 29, 2015 14:13
fizzbuzz elixir
defmodule FizzBuzz do
defp run(0, 0, _), do: "FizzBuzz"
defp run(0, _, _), do: "Fizz"
defp run(_, 0, _), do: "Buzz"
defp run(_, _, z), do: z
def of(n), do: run( rem(n,3), rem(n,5), n)
end
@tdantas
tdantas / swap.ex
Created January 13, 2015 21:04
Swap elixir
defmodule Swap do
def of([ ], _, _), do: [ ]
def of(list, left, left), do: list
def of(list, left, right) do
list
|> List.replace_at(left, nth(list, right))
|> List.replace_at(right, nth(list, left))
end
@tdantas
tdantas / max.ex
Created January 27, 2015 09:55
Max element inside collection
defmodule Max do
def of([ head ]), do: head
def of([ first, second | tail]) do
case first >= second do
true -> of([ first | tail])
false -> of([ second | tail])
end
end
@tdantas
tdantas / sh.sh
Created March 5, 2015 16:58
filter couch
curl -H 'Content-Type: application/json' -X PUT http://localhost:5984/DATABASE/_design/NAME -d \
'{
"filters":{
"filterName":"function(doc, req) {
return true;
}"
}
}'
@tdantas
tdantas / md.css
Created April 19, 2015 21:11
markdown css
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}
var page;
window.onload = function() {
page = document.getElementsByTagName('html');
page.addEventListener('DOMMouseScroll', <HANDLER>, false);
}
window.mimicWheel = function() {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent('DOMMouseScroll', <OPTIONS> )
@tdantas
tdantas / keybase.md
Created June 11, 2015 17:44
keybase.md

Keybase proof

I hereby claim:

  • I am tdantas on github.
  • I am tdantas (https://keybase.io/tdantas) on keybase.
  • I have a public key whose fingerprint is 1DB8 9719 1769 124D BD40 42B9 9DD5 A342 1345 BB52

To claim this, I am signing this object:

@tdantas
tdantas / closure.js
Created July 6, 2015 17:06
node module closure
$ node
> var m = require('module');
undefined
> require.toString()
'function require(path) {\n return self.require(path);\n }'
> module.require.toString()
'function (path) {\n assert(path, \'missing path\');\n assert(util.isString(path), \'path must be a string\');\n return Module._load(path, this);\n}'
> m.wrapper
[ '(function (exports, require, module, __filename, __dirname) { ',
'\n});' ]
@tdantas
tdantas / steve.js
Last active August 29, 2015 14:25
steve jwt
const fs = require('fs');
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const modulePath = path.join(__dirname, 'modules');
const resources = fs.readdirSync(modulePath);