Skip to content

Instantly share code, notes, and snippets.

View TommyZG's full-sized avatar

Tomislav TommyZG

View GitHub Profile
@TommyZG
TommyZG / laravel_da().php
Last active April 3, 2018 07:27
Laravel - dump all passed variables to array for easier read - alias for dd($x->toArray())
//add this to /vendor/laravel/framework/src/Illuminate/Support/helpers.php
if (! function_exists('da')) {
/**
* Dump the passed variables to array and end the script.
*
* @param mixed
* @return void
*/
function da()
// ******************* Scroll to element's position
//get parameters are iteration of all objects selected by .selection
$(".selection").get(0).scrollIntoView();
// ******************* Check if checkbox is checked
$(".checkbox").on("change", function () {
if ($(this).is(":checked")) {
doSomething();
} else {
doSomething();
let person = {
_name: 'Lu Xun',
_age: 137,
set age(newAge) {
if (typeof newAge === 'number') {
this._age = newAge;
} else {
return 'Invalid input'
}
},
@TommyZG
TommyZG / class.js
Last active November 12, 2017 10:52
//declare class
class Surgeon {
//define constructor method - things that will be done on instantiation ('new')
constructor(name, department) { //when 'new-ing' instance of this class, expect 'name' and 'department' arguments
//we use underscore to define properties that aren't supposed to be acccessed directly
this._name = name;
this._department = department;
this._remainingVacationDays = 20;
}
//getter method - name as the property, but without underscore. This will be called with object.name
class HospitalEmployee {
constructor(name) {
this._name = name;
this._remainingVacationDays = 20;
}
static generatePassword(){
return Math.floor(Math.random()*10000);
}
//Initialize your project using npm init (in project folder) and create a directory called src
//Install babel dependencies by running
npm install babel-cli -D
npm install babel-preset-env -D
//Create a .babelrc file inside your project and add the following code inside it:
{
"presets": ["env"]
}
//Add the following script to your scripts object in package.json:
"build": "babel src -d lib"
@TommyZG
TommyZG / artisan.sh
Last active November 19, 2017 15:26
Laravel 5.5 commands reference
php artisan make:migration create_users_table --create=users
php artisan migrate
# To rollback the latest migration operation, you may use the rollback command. This command rolls back the last "batch" of migrations, which may include multiple migration files:
php artisan migrate:rollback
#The migrate:reset command will roll back all of your application's migrations:
php artisan migrate:reset
@TommyZG
TommyZG / git.sh
Last active October 30, 2022 17:19
Push existing project to Bitbucket
# Create repo @BitBucket
# cd /path/to/local/folder
git init
git add .
git remote add origin https://username@bitbucket.org/username/repo.git
git commit -m "Initial"
git push -u origin master
@TommyZG
TommyZG / jquery.promise.js
Last active December 16, 2019 20:54
Example of jQuery Promise/Deferred usage
$(document).ready(function() {
getSomething().done(function() {
$("#success-alert").show();
}).fail(function() {
$("#fail-alert").show();
});
});
@TommyZG
TommyZG / jquery.fadeInOut.js
Created February 4, 2018 14:56
fadeIn and fadeOut with jQuery
// fadeIn
$('.selection').css({opacity: 0.0, visibility: "visible"}).animate({opacity: 1.0});
// fadeOut
$('.selection').css({opacity: 1.0, visibility: "visible"}).animate({opacity: 0});