Skip to content

Instantly share code, notes, and snippets.

View LSViana's full-sized avatar
📱
Web and Mobile

Lucas Viana LSViana

📱
Web and Mobile
View GitHub Profile
@LSViana
LSViana / pom.xml
Created May 3, 2018 16:54
Spring 5 (MVC, RESTFul) + Hibernate 5 (EntityManager) + JWT + Java Mail
<dependencies>
<!-- Apache Commons: DBCP https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>
<!-- Jackson : Databind https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
@LSViana
LSViana / HttpService.java
Created May 10, 2018 18:45
Class to perform HTTP requests at Android Java Mobile
package intro.api.senai.com.apiusage.utils;
import android.os.AsyncTask;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
@LSViana
LSViana / RetrofitConfig.java
Created May 18, 2018 17:02
Retrofit Configuration Class
package intro.api.senai.com.apiusage.retrofit.config;
import intro.api.senai.com.apiusage.utils.AppUtils;
import intro.api.senai.com.apiusage.utils.CEPRestService;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
public class RetrofitConfig {
private Retrofit retrofit;
@LSViana
LSViana / CEPRestService.java
Created May 18, 2018 17:04
Interface to fetch API using Retrofit
package intro.api.senai.com.apiusage.utils;
import intro.api.senai.com.apiusage.models.CEP;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
public interface CEPRestService {
@GET("{cep}")
public static void Copy(this Object destiny, Object origin, IEnumerable<string> fieldsToIgnore)
{
fieldsToIgnore = fieldsToIgnore.ToArray();
//
var typeDestiny = destiny.GetType();
var propsDestiny = typeDestiny.GetProperties();
var typeOrigin = origin.GetType();
var propsOrigin = typeOrigin.GetProperties();
foreach (var prop in propsDestiny)
{
@LSViana
LSViana / loading-vue-components-from-folder.js
Last active September 23, 2019 01:58
Register all Vue components inside 'components' folder and children folders
import Vue from 'vue'
// Importing all components inside './components' folder
const req = require.context('./components/', true, /\.(js|vue)$/i);
req.keys().map(key => {
const fileNameKey = key.substr(key.lastIndexOf('/') + 1);
const name = fileNameKey.match(/\w+/)[0];
return Vue.component(name, req(key).default)
});
@LSViana
LSViana / MemoryMagician.cpp
Created July 21, 2018 15:06
Using memory alignment to mount a 12-byte object with an int and unsigned long long
class MemorySpace {
public:
void setSecond(long long second) {
this->second_1 = second & 0x00000000ffffffff;
this->second_2 = (second & 0xffffffff00000000) >> 32;
}
long long getSecond() {
return this->second_1 + (((unsigned long long )this->second_2) << 32);
}
private:
@LSViana
LSViana / ChangingCollections.cs
Last active August 18, 2018 22:13
Updating Collections properly using EF Core
class Controller {
public IActionResult Put(Model posted) {
foreach (var item in fromDb.Collection)
{
var editedItem = posted.Collection.FirstOrDefault(a => item.Id == a.Id);
if(editedItem is null)
Db.Remove(item);
else
Db.Entry(item).CurrentValues.SetValues(editedItem);
}
// ASP.NET Framework
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
// ASP.NET Core
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
foreach (var navigation in entityType.GetNavigations())
{
navigation.ForeignKey.DeleteBehavior = DeleteBehavior.Restrict;
}
@LSViana
LSViana / bindprop.snippet
Last active September 15, 2018 15:52
Bindable Property Creator Snippet
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>bindprop</Title>
<Shortcut>bindprop</Shortcut>
<Description>Code snippet for Creating a Bindable Property</Description>
<Author>Lucas Viana</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>