Skip to content

Instantly share code, notes, and snippets.

View bhrott's full-sized avatar
⚔️
killing zombies

Ben-Hur Santos Ott bhrott

⚔️
killing zombies
View GitHub Profile
@bhrott
bhrott / nginx_comandos_salva_bundas.md
Created December 4, 2017 18:04
Nginx: comandos salva-bundas

Quando o nginx estiver com erro de permissão para acessar localhost, rode este comando:

/usr/sbin/setsebool httpd_can_network_connect true 
@bhrott
bhrott / vs_code_settings.js
Last active October 16, 2017 22:02
My VS Code Settings
{
"workbench.colorTheme": "Hop Light",
"workbench.iconTheme": "material-icon-theme",
"workbench.fontAliasing": "antialiased",
"window.zoomLevel": 1.2,
// Pre VS Code 1.15
"emmet.syntaxProfiles": {
"javascript": "jsx"
},
@bhrott
bhrott / handle-uncaught-errors.js
Created October 9, 2017 02:32
NodeJS: handle uncaught errors
// add this code before all:
process.on('uncaughtException', function(err) {
console.error(err.stack);
console.log('UNCAUGHT_EXCEPTION: ' + err);
});
@bhrott
bhrott / nodejs-custom-es6-errors.md
Created October 5, 2017 17:37 — forked from slavafomin/nodejs-custom-es6-errors.md
Custom ES6 errors in Node.js

Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.

I've tried to make it as lean and unobtrusive as possible.

Defining our own base class for errors

errors/AppError.js

@bhrott
bhrott / get_app_version.swift
Created July 24, 2017 20:45
IOS :: Swift :: Get app version
func getAppVersion() -> String? {
if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
return version
}
return nil
}
@bhrott
bhrott / save_temp_file_swift.swift
Created July 20, 2017 23:22
Save temporary file swift 3
private func createTempFile(_ file: Data) throws -> URL {
let dir = NSTemporaryDirectory()
let fileName = NSUUID().uuidString
let url = NSURL.fileURL(withPathComponents: [dir, fileName])!
try file.write(to: url)
return url
}
@bhrott
bhrott / Apply max length to UITextField in swift.swift
Created July 10, 2017 01:29
Apply max length to UITextField in swift
extension MyViewController: UITextFieldDelegate {
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
guard let text = textField.text else { return true }
let newLength = text.characters.count + string.characters.count - range.length
return newLength <= 30 // replace 30 for your max length value
}
}
@bhrott
bhrott / toast_swift.md
Last active July 9, 2017 18:18
Simple top toast on swift 3

Usage

Toast.show(withMessage: "My message")

Result

toast

@bhrott
bhrott / css_card_size.css
Created May 27, 2017 18:12
Css Card Size
.card {
width: 230.551181102px;
height: 325.039370079px;
border: 5px solid #8B7355;
overflow: hidden;
float: left;
position: relative;
margin: 10px 10px;
background-image: url(img/parchment-bg.jpg);
@bhrott
bhrott / notificationService.swift
Created March 31, 2017 16:39
Swift :: Service for Notifications
import Foundation
class NotificationService {
static private var _instance: NotificationService! = nil
static var sharedInstance: NotificationService {
get {
if NotificationService._instance == nil {
NotificationService._instance = NotificationService()