Skip to content

Instantly share code, notes, and snippets.

@e23z
e23z / activity.cs
Created September 28, 2017 20:24
[App Custom Scheme] How to create a custom scheme for mobile apps. #xamarin #mobile #android #app
using Android.App;
using Android.Content;
using Android.OS;
namespace CleanMyTwitter.Android {
[Activity(Label = "SchemeActivity", NoHistory = true)]
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataSchemes = new[] { "http", "https" }, DataHost = "myurl.com", AutoVerify = true)]
public class SchemeActivity : Activity {
protected override void OnCreate(Bundle savedInstanceState) {
base.OnCreate(savedInstanceState);
@e23z
e23z / WrapLayoutManager.cs
Created August 23, 2017 21:01
[WrapLayoutManager for RecyclerView on Android] A fix for an issue with wrap_content within LinearLayoutManager for RecyclerView with v7 support on Xamarin. #xamarin #android #mobile
/*
Reference:
https://stackoverflow.com/questions/27475178/how-do-i-make-wrap-content-work-on-a-recyclerview
*/
public class WrapLayoutManager : LinearLayoutManager {
private const int DefaultChildSize = 100;
private static readonly Rect TmpRect = new Rect();
private int _childSize = DefaultChildSize;
private static bool _canMakeInsetsDirty = true;
@e23z
e23z / extensions.cs
Last active August 7, 2017 21:33
[Entity Framework Core Custom Raw SQL Types] How to use raw queries with custom datatypes in entity framework core. #csharp #netcore #entityframework #database
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Common;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
@e23z
e23z / export.cs
Last active August 3, 2017 14:43
[RSA Keys Import & Export] How to import and export C# generated RSA keys to and from the PEM format. #cryptography #security #rsa #csharp #function
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace myapp {
public static class PEMExporter {
public static string Export(RSA rsa, bool exportPrivateKey) {
var parameters = rsa.ExportParameters(includePrivateParameters : exportPrivateKey);
var key = new StringBuilder();
@e23z
e23z / aes.cs
Created August 3, 2017 00:59
[AES Encryption with C#] How to encrypt strings using the AES cipher. #cryptography #security #csharp
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace myapp {
public static class AESCipher {
public static string EncryptString(string key, string str) {
string encryptedStr = null;
@e23z
e23z / infiniteScroll.m
Created July 26, 2017 16:03
[Infinite UIScrollView] Example on how to develop an infinite scrolling UIScrollView for mocks. #ios #objectivec #mobile #ui
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if(scrollView.contentOffset.x == 0) {
CGPoint newOffset = CGPointMake(scrollView.bounds.size.width+scrollView.contentOffset.x, scrollView.contentOffset.y);
[scrollView setContentOffset:newOffset];
[self rotateViewsRight];
}
else if(scrollView.contentOffset.x == scrollView.bounds.size.width*2) {
CGPoint newOffset = CGPointMake(scrollView.contentOffset.x-scrollView.bounds.size.width, scrollView.contentOffset.y);
[scrollView setContentOffset:newOffset];
@e23z
e23z / animatedReload.swift
Created July 26, 2017 15:58
[Animated UITableView Reload] How to animate an UITableView when it reloads its data. #ios #swift #animation #ui
UIView.transitionWithView(tableView,
duration: 0.35,
options: .TransitionCrossDissolve,
animations: { () -> Void in
self.tableView.reloadData()
},
completion: nil);
/*
possible animations:
@e23z
e23z / blur.swift
Last active July 26, 2017 14:50
[Blurred Overlay] How to apply a blurred overlay to a view. #swift #ios #ui
//only apply the blur if the user hasn't disabled transparency effects
if !UIAccessibilityIsReduceTransparencyEnabled() {
self.view.backgroundColor = UIColor.clear
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
//always fill the view
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
@e23z
e23z / padding.m
Created July 26, 2017 14:48
[UILabel Text Padding] How to apply padding to a UILabel view. #ios #objectivec #ui #swift
// Option 1
- (void)drawTextInRect:(CGRect)rect {
UIEdgeInsets insets = {0, 5, 0, 5};
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
}
// Option 2
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
style.alignment = NSTextAlignmentJustified;
style.firstLineHeadIndent = 10.0f;
@e23z
e23z / tint.swift
Created July 26, 2017 14:45
[Tint Image in CALayer] How to tint an image that is in a CALayer object. #swift #mobile #ios #ui
- (UIImage *)tintedImageWithColor:(UIColor *)tintColor blendingMode:(CGBlendMode)blendMode highQuality:(BOOL) yerOrNo;
{
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
if (yerOrNo) {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(context, true);
CGContextSetAllowsAntialiasing(context, true);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
}
[tintColor setFill];