Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Thiago Dantas tdantas

🏠
Working from home
View GitHub Profile
@tdantas
tdantas / model.js
Created Apr 30, 2014
mongoose test post middleware
View model.js
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 Aug 29, 2015
fizzbuzz elixir
View fizzbuzz.ex
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
View swap.ex
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 Jan 27, 2015
Max element inside collection
View max.ex
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 Mar 5, 2015
filter couch
View sh.sh
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 Apr 19, 2015
markdown css
View md.css
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}
View wheel
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> )
View 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 Jul 6, 2015
node module closure
View closure.js
$ 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 Aug 29, 2015
steve jwt
View steve.js
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);