Skip to content

Instantly share code, notes, and snippets.

Working from home

Thiago Dantas tdantas

Working from home
View GitHub Profile
tdantas / userService.js
Last active Nov 3, 2019
Port simple JS function to Clojure ( make it simple to test and isolating side-effects )
View userService.js
1. create user database
2. send confirmation email
3. commit or rollback transaction
- 1 and 2 must be somehow transactional
( if sendgrid rejects the email "http response status 400 - 500 range", you must rollback the transaction )
View booking.clj
(ns datomicdemo.core
[clojure.string :as str]
[datomic.api :as d]))
(def url "datomic:free://localhost:4334/datomicdemo")
(d/create-database url)
View vars.clj
;; (defn full-name ...) is equivalent to:
;; (def full-name (fn []...)) which defines a Var
;; object called full-name pointing at a compiled function
;; returning the static string "Oliv"
(defn full-name [] "Oliv")
;; greetings is a function taking two args.
;; it returns a function of no argument
;; invoking the second argument (f) with no arguments
;; and combining a string with it.

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>
View short.clj
(ns urlshortener.core
[org.httpkit.server :refer [run-server]]
[taoensso.carmine :as redis])
(def validator (UrlValidator. (into-array ["http" "https"])))
tdantas / index.js
Last active Mar 7, 2016
using npm with gist
View index.js
module.exports = console.log.bind(console, 'hello world');
View admin.js
//path: plugins/admin.js
const plugin = module.exports;
plugin.register = register;
plugin.register.attributes = {
name: 'admin plugin',
version: '0.0.1-alpha-beta-gama'
tdantas / queue-function.js
Created Feb 3, 2016
delaying the execution of your function until ready be called
View queue-function.js
const _ = require('lodash');
module.exports = queue;
function queue(fn) {
var queuedArgs = [];
var ready = false;
queuedFn.ready = function() {
ready = true;
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);
tdantas / closure.js
Created Jul 6, 2015
node module closure
View closure.js
$ node
> var m = require('module');
> 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});' ]