Skip to content

Instantly share code, notes, and snippets.

View jonatasemidio's full-sized avatar

Jonatas Emidio jonatasemidio

View GitHub Profile
@jonatasemidio
jonatasemidio / github_api_samples.txt
Last active April 20, 2016 17:46
GitHub API Samples Script cURL
Get a File
curl -i -X GET -H 'Authorization: token <your token>' -d '{"path": "index.html", "message": "Initial Commit", "committer": {"name": "Jonatas Emidio", "email": "jonatasemidio@gmail.com"}, "branch": "master"}' https://api.github.com/repos/jonatasemidio/blog/contents/index.html
Create a File
curl -i -X PUT -H 'Authorization: token <your token>' -d '{"path": "index.html", "message": "Initial Commit", "committer": {"name": "Jonatas Emidio", "email": "jonatasemidio@gmail.com"}, "content": "VGVzdGluZyBHaXRIdWIgQVBJ", "branch": "master"}' https://api.github.com/repos/jonatasemidio/blog/contents/index.html
Update a File
curl -i -X PUT -H 'Authorization: token <your token>' -d '{"path": "index.html", "message": "Initial Commit", "committer": {"name": "Jonatas Emidio", "email": "jonatasemidio@gmail.com"}, "content": "VGVzdGluZyBHaXRIdWIgQVBJ", "sha":"2706f84a7078ad64fbdca10558879e6f2c323694", "branch": "master"}' https://api.github.com/repos/jonatasemidio/blog/contents/index.html
Delete a File
@jonatasemidio
jonatasemidio / dirfilelogger.groovy
Last active February 12, 2016 12:23
Generate a Log in a specific file all the recursive files in a dir
f = new File('dir_file_'+ System.currentTimeMillis() +'.log')
new File('.').eachFileRecurse { f << it.getCanonicalPath() + '\n' }
REGEX = "^[\\w\\s/<>?\".=-]*[áéíóúçàãõâêô:\\s]*\$"
nome = " jonatas#!@#%¨&* emidio"
texto = '''
<?xml¨&*()¨&*( version="1.0" encoding="ISO-8859-1"?>
<SAIDA>
<HEADER>
<ERRO>
<CODIGO-ERRO>1454014207309</CODIGO-ERRO>%¨&*()
<ORIGEM-ERRO>The data "ˆ" is not legal for a JDOM character content 0x0 is not a legal XML character.</ORIGEM-ERRO>
@jonatasemidio
jonatasemidio / retainAllSample.groovy
Created January 8, 2016 18:50
retainAll method samples
// Font: http://mrhaki.blogspot.fr/2015/09/groovy-goodness-removing-elements-from.html
// Thanks to Hubert Klein Ikkink (https://github.com/mrhaki)
def list = ['Groovy', 42, 'gr8!', 5.2, new Date()]
// Groovy adds retainAll method
// to remove items from collection
// that do not apply to the condition we
// define in the closure and keep those
// items that do apply to the condition.
// Font: http://mrhaki.blogspot.fr/2015/09/groovy-goodness-removing-elements-from.html
// Thanks to Hubert Klein Ikkink (https://github.com/mrhaki)
def list = ['Groovy', '=', 'gr8!']
// Groovy adds removeAll method
// to remove items from collection
// that apply to the condition we
// define in the closure.
list.removeAll { it.toLowerCase().startsWith('g') }
@jonatasemidio
jonatasemidio / JsonToHTML.groovy
Last active November 3, 2015 17:19
Gerador de HTML apartir do JSON
m = [name: 'nome do cara']
s = "{name:'jonatas', idade: 10}".replace("'", "")
s = s.replace('{', '').replace('}', '')
println s.split(', ').each{
name = it.split(':')[0]
value = it.split(':')[1]
@jonatasemidio
jonatasemidio / testededna.txt
Last active September 9, 2015 17:00
Teste de DNA
O apresentador Ratinho precisa criar um quadro em seu programa chamado de "Teste de DNA".
Esse quadro será responsável por identificar quem é o pai da criança apresentada.
Basicamente será apresentado uma criança e dois possíveis pais. Onde o Ratinho será o responsável por descobrir o pai original.
Para isso o DNA coletado de cada possível pai será comparado com o DNA coletado do filho.
As 3 sequências de DNS serão informadas ao sistema que retornará com quem é o Pai.
Onde você será o responsável por contruir esse sistema seguindo as seguintes regras:
1 - O DNA com a maior pontuação (mais parecido) de compatibilidade será eleito o pai da vez;
@jonatasemidio
jonatasemidio / TestGenerator.groovy
Last active August 29, 2015 14:25
TestGenerator
import groovy.io.FileType
def generateTest(String dir, String projectName) {
createDirectories(dir+File.separator+projectName)
new File(dir).eachFileRecurse(FileType.FILES) { if(it.name.contains('.java')) buildTestClasses(it.toString(), projectName)}
}
def buildTestClasses(String completeFileName, String projectName){
def selectedFile = new File(completeFileName)
def testClassFile = new File(createNameTestFile(completeFileName, projectName))
interface Buyable {
def buy()
}
class SomeBuyableObject implements Buyable {
String foo
def buy() { //do stuff }
}
class AnotherBuyableObject implements Buyable {
@jonatasemidio
jonatasemidio / listaAnimais.groovy
Last active August 29, 2015 14:24
Listando classes diferentes com metodos iguais
Object.metaClass.findAll{println it.toString()}
class Dog{ String name; public String toString(){ return this.name } }
class Cat{ String name; public String toString(){ return this.name } }
class Cow{ String name; public String toString(){ return this.name } }
dog = new Dog(name: 'toto')
​cat = new Dog(name: 'lili')
cow = new Dog(name: 'mumu')