Skip to content

Instantly share code, notes, and snippets.

View fernandodof's full-sized avatar
🎯
Focusing

Fernando Ferreira fernandodof

🎯
Focusing
View GitHub Profile
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display the fixed number.</p>
<button onclick="myFunction('99999999999998.5900', '', 0, '.', ',')">Try it</button>
<p>1</p>
<p id="demo"></p>
@fernandodof
fernandodof / array.chunk.js
Last active April 7, 2016 12:21 — forked from webinista/array.chunk.js
Array.prototype.chunk: Splits an array into an array of smaller arrays containing `groupsize` members
/*
Split an array into chunks and return an array
of these chunks.
This will *not* preserve array keys.
*/
Array.prototype.chunk = function(groupsize){
var sets = [], chunks, i = 0;
chunks = this.length / groupsize;
tinymce.addI18n('pt_BR',{
"Cut": "Recortar",
"Heading 5": "Cabe\u00e7alho 5",
"Header 2": "Cabe\u00e7alho 2",
"Your browser doesn't support direct access to the clipboard. Please use the Ctrl+X\/C\/V keyboard shortcuts instead.": "Seu navegador n\u00e3o suporta acesso direto \u00e0 \u00e1rea de transfer\u00eancia. Por favor use os atalhos Ctrl+X - C - V do teclado",
"Heading 4": "Cabe\u00e7alho 4",
"Div": "Div",
"Heading 2": "Cabe\u00e7alho 2",
"Paste": "Colar",
"Close": "Fechar",
@fernandodof
fernandodof / CRUDService.java
Last active February 17, 2017 16:43
Enum problem with querydsl
public interface CRUDService<T, K> {
public T create(T entity) throws ServiceException;
public T update(T entity) throws ServiceException;
public void remove(T entity) throws ServiceException;
public T findById(K id) throws ServiceException;
public Iterable<T> findAll() throws ServiceException;
public Page<T> findByFilter(String filter, String value, Pageable pageable) throws ServiceException;
default public Page<T> findByFilter(Predicate predicate, Pageable pageable) throws ServiceException {
return null;
@fernandodof
fernandodof / app.js
Last active March 1, 2020 17:13
GraphQL first steps
const { ApolloServer, gql } = require('apollo-server-express');
const fs = require('fs');
const express = require('express');
const port = 3000;;
const app = express();
// Build a schema using GraphQL schema language from the schema file
const typeDefs = gql(fs.readFileSync('./schema.graphql', { encoding: 'utf-8' }));
type User {
id: ID!,
name: String!,
description: String,
email: String!,
age: Int,
followers: [User]
}
type Tweet {
const db = require('./database');
const Query = {
users: () => db.users.list(),
user: (root, { id }) => db.users.get(id),
tweets: (root, { userId, last }) => {
const tweets = db.tweets.list().filter(tweet => tweet.userId === userId);
return last ? tweets.slice(-last) : tweets;
}
};
// Omitted query resolver
const User = {
followers: (user) => {
const followersIds = db.users.get(user.id).followers;
const followers = [];
for (id of followersIds) {
followers.push(db.users.get(id));
}
return followers;
async function graphqlRequest(query, variables = {}) {
const request = {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ query, variables })
};
const response = await fetch('http://localhost:3000/graphql', request);
const responseBody = await response.json();
return responseBody.data;
<body>
<button onclick="getUser()">Get user</button>
<script src="graphql-requests.js"></script>
</body>