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 / AppDelegate.m
Created December 16, 2018 10:44
react-native-push-notification in a foreground/background app snippet (put this inside the implementation of AppDelegate.m)
/ Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
@LSViana
LSViana / ToViewExtension.cs
Created October 13, 2018 13:42
Creating a simplified version of ConstraintExpression with Type=RelativeToView
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Xaml;
namespace Playground.Helpers
{
@LSViana
LSViana / ToParentExtension.cs
Created October 13, 2018 13:42
Creating a simplified version of ConstraintExpression with Type=RelativeToParent
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Playground.Helpers
{
[ContentProperty(nameof(Value))]
@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>
// 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 / 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);
}
@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 / 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)
});
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 / 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}")