Skip to content

Instantly share code, notes, and snippets.

View paulosuzart's full-sized avatar

Paulo Suzart paulosuzart

View GitHub Profile
@paulosuzart
paulosuzart / writer.js
Created July 7, 2017 16:58
generation of fake data
const fs = require('fs');
const csvWriter = require('csv-write-stream')
const writer = csvWriter({ headers: ["id", "name"]});
const faker = require('faker');
writer.pipe(fs.createWriteStream('out.csv'))
for (var i = 1; i < 2000000; i++) {
private:
StackContextEntry* getFromContext(StackElements element) {
// as we emplace back in the stack, we should find from back to front
for (auto it = m_stack.rbegin(); it != m_stack.rend(); it++) {
if ((*it).elementType == element) {
return &(*it);
}
}
return NULL;
}
immutable string GenerateVisitMethods = q{
mixin defaulVisit!(["Document", "Definition", "FragmentDefinition",
"OperationDefinition", "SelectionSet", "Selection",
"Field", "VariableDefinitions", "VariableDefinition",
"Type", "TypeName", "FragmentSpread", "Argument", "Arguments"]);
mixin (defaulVisit);
};
mixin template defaulVisit(alias name)
{
@paulosuzart
paulosuzart / ReduxFetcher.js
Last active January 6, 2021 05:52
a simple abstraction for fetching, updating and filtering objects with correspondending state.
import {
XPTOService
} from '../services'
import { loginFailed } from './index.js'
const initial = {
filtering: {
data: []
},
listing: {}
@paulosuzart
paulosuzart / bible.yaml
Last active June 9, 2016 02:05
Simple module to randomly generate bible verses
---
gn: [31, 25, 24, 26, 32, 22, 24, 22, 29, 32, 32, 20, 18, 24, 21, 16, 27, 33, 38, 18, 34, 24, 20, 67, 34, 35, 46, 22, 35, 43, 54, 33, 20, 31, 29, 43, 36, 30, 23, 23, 57, 38, 34, 34, 28, 34, 31, 22, 33, 26]
ex: [22, 25, 22, 31, 23, 30, 29, 28, 35, 29, 10, 51, 22, 31, 27, 36, 16, 27, 25, 26, 37, 30, 33, 18, 40, 37, 21, 43, 46, 38, 18, 35, 23, 35, 35, 38, 29, 31, 43, 38]
lv: [17, 16, 17, 35, 26, 23, 38, 36, 24, 20, 47, 8, 59, 57, 33, 34, 16, 30, 37, 27, 24, 33, 44, 23, 55, 46, 34]
nm: [54, 34, 51, 49, 31, 27, 89, 26, 23, 36, 35, 16, 33, 45, 41, 35, 28, 32, 22, 29, 35, 41, 30, 25, 19, 65, 23, 31, 39, 17, 54, 42, 56, 29, 34, 13]
dt: [46, 37, 29, 49, 33, 25, 26, 20, 29, 22, 32, 31, 19, 29, 23, 22, 20, 22, 21, 20, 23, 29, 26, 22, 19, 19, 26, 69, 28, 20, 30, 52, 29, 12]
@paulosuzart
paulosuzart / orelse.scala
Created September 22, 2015 01:37
orElse
implicit class OrElseHelper[S, Z](from: (S => Future[Option[Z]])) {
// TODO: Verify if this helper is generalized enough to move to a more central generic area.
def orElse(to : (Z => Future[Z]))(s : S)(c : Z): Future[Either[Future[Z],Future[Z]]] = {
from(s) flatMap {
case None => Future.successful(Left(to(c)))
case Some(someValue) => Future.successful(Right(Future.successful(someValue)))
}
}
}
def delete(groupName: String, teamName: String, seqNumber: Int) = (baseAction andThen authAction) { request =>
apiActor ! DeleteCommand(CommandKey(seqNumber, teamName, groupName))
Ok("Command enqueued for deletion")
}
def delete(command: Future[Command]): Future[Int] = command.flatMap { c =>
val q = commands.filter(_.id === c.id).map(_.deleted)
Logger.debug(q.updateStatement)
@paulosuzart
paulosuzart / Main.hs
Last active August 29, 2015 14:27
Good Node Hacker Rank - finished
{-|
Module : Good Node
Description : impl for Hacker Rank
Used at blog post: <http://paulosuzart.github.io/blog/2015/08/21/how-much-functional-are-you/>
-}
module Main(
Node,
NodeSystem,
makeNodeAssoc,
@paulosuzart
paulosuzart / goodNode.scala
Last active August 29, 2015 14:27
Hacker Rank Goodnode challenge
package com.example
import scala.collection.mutable.HashMap
class Node(idx : Int) {
val index = idx
var pointsTo : Option[Node] = None
var walked = false
override def toString() = s"Node - idx: ${this.index}, points to ${this.pointsTo.get.index}."
}
@paulosuzart
paulosuzart / s_and_b.groovy
Last active August 29, 2015 14:27
Sherlock and The Beast
//Enter your code here. Read input from STDIN. Print output to STDOUT
def br = new BufferedReader(new InputStreamReader(System.in))
def lineAsInt(br) {
return Integer.parseInt(br.readLine())
}
def MAX_T = 20
def readT(br) {
def t = lineAsInt(br)