Skip to content

Instantly share code, notes, and snippets.

class Person {
// String and int variables don't allow `null`
// They wanna be initialized
// `late` says to compiler to not worry as these vars will be init later
late String name;
late int age;
// constructor with named parameters, with default values
Person({String inputName = '', int age = 30}) {
name = inputName;
@bernbecht
bernbecht / ts-design-patterns-strategy.ts
Created June 28, 2021 16:29
Strategy Design Patter in TS
// Strategy design pattern
interface QuackBehavior {
quack(): void;
}
class Quack implements QuackBehavior {
quack() {
console.log('quack');
}
}
@bernbecht
bernbecht / .gitignore
Created February 10, 2021 11:52
React Native Git Ignore
# Xcode
!**/*.xcodeproj
!**/*.pbxproj
!**/*.xcworkspacedata
!**/*.xcsettings
!**/*.xcscheme
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
@bernbecht
bernbecht / es6.1.js
Last active August 21, 2018 13:39
Learn ES6 /Variables and Parameters
console.clear();
///////////////////////
// Destructure
//
console.log('///////////////////////\n// Destructure\n///////////////////////');
{
let doWork = ()=> {
return {
firstName: 'Bernardo',
lastName: 'Bechtold',
@bernbecht
bernbecht / scopeValidator.js
Last active January 23, 2017 16:31
braces/brackets/parentheses validator without order checking
var openingSymbols = ['{', '[', '('],
closingSymbols = ['}', ']', ')'],
counter = 0;
function scopeValidator(char) {
if (openingSymbols.indexOf(char) != -1) counter++;
else if (closingSymbols.indexOf(char) != -1) counter--;
}
function scopeParser(text) {
@bernbecht
bernbecht / queue.js
Last active January 23, 2017 16:11
Queue using 2 stacks in Javascript
function Stack() {
this._size = 0;
this._storage = {};
}
Stack.prototype.push = function(data) {
var size = ++this._size; //returns i++
this._storage[size] = data;
return size;
}
@bernbecht
bernbecht / isFieldEmpty.php
Created September 20, 2016 10:50
Checking if a field is really empty
<?php
function isFieldEmpty($field) {
return isset($field) && trim($field) == '';
}
$data = '0';
echo isFieldEmpty($data);
?>
@bernbecht
bernbecht / functional-1.js
Created July 9, 2016 22:11
Map, filter and reduce for functional programming
var people = [
{'name': 'Mary', 'height': 160},
{'name': 'Isla', 'height': 80},
{'name': 'Sam'}
];
var peopleWithHeight = people.filter(function(person) {
return person.hasOwnProperty('height');
});
require('shelljs/global');
var moduleName = "moduleName",
mainPath = "app/modules/",
visibility = "public",
full_path = mainPath + visibility + "/" + moduleName + "/";
console.log("------ Creating module " + moduleName + " as " + visibility + " --------");
console.log("-> full path: " + full_path);
@bernbecht
bernbecht / module.module.js
Created April 6, 2016 16:38
Angular Module Skelleton
(function() {
var configModule = function configModule(
$stateProvider,
$urlRouterProvider)
{
$stateProvider
.state('public.%', {
url: "/%",
templateUrl: 'modules/public/%/templates/%.view.html',