Skip to content

Instantly share code, notes, and snippets.

@salvar-labs
salvar-labs / UIAlertControllerFromUIView.swift
Created February 4, 2021 22:33
Present an UIAlertController from an UIView
/// ...
let ac = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
UIApplication.shared.keywindow?.rootViewController?.presentedViewController?.present(ac, animated: true, completion: nil)
/// ...
@salvar-labs
salvar-labs / AppleUIAlertControllerExample.swift
Created February 4, 2021 22:35
Apple's UIAlertController example
let alert = UIAlertController(title: "My Alert", message: "This is an alert.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: { _ in
NSLog("The \"OK\" alert occured.")
}))
self.present(alert, animated: true, completion: nil)
@salvar-labs
salvar-labs / ReactAutoBindingFunctions.js
Created February 4, 2021 23:04
React Auto Binding Functions
/**
* Auto-binding functions
*/
import React from 'react';
export default class CustomComponent extends React.Component {
// ...
autoBindingFunction = () => {
@salvar-labs
salvar-labs / ReactClassicFunctionBinding.js
Created February 4, 2021 23:09
React Classic Function Binding
/**
* Classic function binding
*/
import React from 'react';
export default class CustomComponent extends React.Component {
constructor(props) {
super(props);
@salvar-labs
salvar-labs / currentFolderFilesToJSON.js
Created February 4, 2021 23:21
List current folder files in a JSON array with JavaScript
/**
* @name FileListToJson
* @description Script to turn the current folder's files list in a array inside a JSON.
* @author saulosf - salvarLabs
*/
const fs = require('fs')
const path = require('path')
fs.readdir(__dirname, (err, files) => {
@salvar-labs
salvar-labs / MobileFriendlyRenaming.py
Last active February 4, 2021 23:26
Rename files to be mobile friendly
import os
"""
Renames the filenames within the same directory to be mobile friendly
(1) Changes spaces to underscores
(2) Makes lowercase
Usage:
python rename.py
source: https://gist.github.com/igniteflow/1226919
modification: @saulosf - salvar
@salvar-labs
salvar-labs / FindRNEnvironment.js
Created February 4, 2021 23:35
Quickly check development environment in React Native
/// ...
if (__DEV__) {
/// Dev environment...
} else {
/// Production environment...
}
@salvar-labs
salvar-labs / correctErrorClass.ts
Last active April 8, 2023 03:17
Correctly creating an custom Error class in TypeScript
class CustomError extends Error {
__proto__ = Error
constructor(message: string) {
super(message);
Object.setPrototypeOf(this, CustomError.prototype);
}
}
@salvar-labs
salvar-labs / naiveErrorClass.ts
Created February 4, 2021 23:47
Wrong way of creating a custom error class in TypeScript
class CustomError extends Error {
/// ...
constructor(message: string) {
super(message);
/// ...
}
}