Skip to content

Instantly share code, notes, and snippets.

View drFabio's full-sized avatar

Fabio Oliveira Costa drFabio

View GitHub Profile
@drFabio
drFabio / Example.php
Last active August 29, 2015 13:56
HTML PHP Truncator using tidy. IT counts the texts chars to N chars, if the word didn't end yet it ends, and it closes the html tags that it's left open
echo '<pre>';
$subject='<p>Lorem</p>
<pre class="brush:js;auto-links:false;toolbar:false" contenteditable="false"> //$(\'textarea[name=html]\').editor();
tinymce.init({selector:\'textarea[name=html]\',
plugins: [ // plugins list
"preview sh4tinymce wordcount"
],
toolbar: "undo redo | sh4tinymce | preview" // toolbar list
});</pre>
<p> Ipsum dolor sit amet</p>';
@drFabio
drFabio / gist:5ede2a70471218c03c88
Last active August 29, 2015 14:04
CSV Reader in nodeJS
var fs=require('fs');
var lazy = require("lazy")
function CSVReader(linesToSkip,separator,convertKeyFunction){
if(!linesToSkip){
linesToSkip=0;
}
if(!separator){
separator=';';
}
this._linesToSkip=linesToSkip;
@drFabio
drFabio / patchSpy.py
Last active February 6, 2016 13:40
Utility to simplify patch.objec wen it behaves as a spy
from unittest.mock import patch
def spy(target, attribute, **kwargs):
if kwargs.get('wraps') is None:
kwargs['wraps'] = getattr(target, attribute)
return patch.object(target, attribute , **kwargs)
@drFabio
drFabio / techWorthy.js
Created February 14, 2016 21:55
Search for a tech on gitHub and save it somewhere
var http = require('https');
var MongoClient = require('mongodb');
var url = require('url');
function get(path,cb){
var config = url.parse(path);
config.headers = {'user-agent': 'drFabio'};
http.get(config , function(response) {
var body = '';
response.on('data', function(d) {
MyPlugin.prototype.apply = function(compiler) {
compiler.plugin("entry-option", function(context, entry) {
function itemToPlugin(item, name) {
if(Array.isArray(item))
return new MultiEntryPlugin(context, item, name);
else
return new SingleEntryPlugin(context, item, name);
}
compiler.apply(itemToPlugin(entry,'main'));
compiler.apply(itemToPlugin(__dirname+'/someFile.md','target/name'));
const { apolloExpress, graphiqlExpress } = require('apollo-server');
const { makeExecutableSchema } = require('graphql-tools')
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
//Your schema declaration herte
const typeDefs = require('./schema')
const schemaOptions = {
typeDefs,
@drFabio
drFabio / back.js
Created October 21, 2016 22:57
Apollo updatequeries example
const express = require('express')
const { apolloExpress, graphiqlExpress } = require('apollo-server');
const cors = require('cors')
const { makeExecutableSchema } = require('graphql-tools')
const bodyParser = require('body-parser')
const typeDefs = `
type Minimal{
id: ID!
name: String
@drFabio
drFabio / flatten.js
Created September 28, 2017 14:20
Flatten a nested array into a single level array
const assert = require('assert')
/**
* Returns a nested array into a flatten single level array
* @param {Array} input a multiple level array
* @return {Array} an one level array of all the elements inside
*/
function flatten (input) {
return input.reduce((ret, el) => {
if (Array.isArray(el)) {
ret = ret.concat(flatten(el))
@drFabio
drFabio / exemplo.html
Created November 18, 2017 19:48
Recursos para artigo
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
@drFabio
drFabio / unidades.css
Created November 18, 2017 19:56
Unidades relativas
#logo {
height: 10vh;
margin-bottom: 2rem;
}
label {
font-size: 1.5em;
}