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 / DivisionAlgorithm.groovy
Created October 28, 2013 18:25
Division Algorithm in groovy
//Based on https://gist.github.com/israelst/2041698
//See it working http://groovyconsole.appspot.com/script/1265001
def dv(x, y){
result = [q : 0, r : 0]
while (x >= y){
x -= y
result.q += 1
}
result.r = x
@jonatasemidio
jonatasemidio / ConcurrentAccessProblems.java
Created October 22, 2013 12:45
Concurrent Access Problems Threads share memory, and they can concurrently modify data. Since the modification can be done at the same time without safeguards, this can lead to unintuitive results. Data Races or Race condition or Race hazard When two or more threads are trying to access a variable and one of them wants to modify it, you get a pr…
//Let see with an example:
class Counter {
public static long count = 0;
}
class UseCounter implements Runnable {
public void increment() {
Counter.count++;
System.out.print(Counter.count + " ");
def fizzbuzz(n):
if n % 3 == 0 and n % 5 == 0:
return 'FizzBuzz'
elif n % 3 == 0:
return 'Fizz'
elif n % 5 == 0:
return 'Buzz'
else:
return str(n)
@jonatasemidio
jonatasemidio / FSLDC Links Grails
Created July 19, 2013 18:19
V FSLDC 2013:Links Interessantes
@jonatasemidio
jonatasemidio / 1DataSourceUnitTest.groovy
Last active December 17, 2015 19:09
Mock UnitTest with DataSource
import grails.test.mixin.TestFor
@TestFor(DadosService)
class DadosServiceTests {
void test_obtemDados() {
def dadosBuscasService = new DadosBuscasService()
def result = ['CVT', '2', '2', 'AAAA', 'Grat']
def sqlUtilService = [select: {result}] as SqlUtilService
dadosBuscasService.sqlUtilService = sqlUtilService