Skip to content

Instantly share code, notes, and snippets.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Mikhail Davydov <azazel.private@gmail.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE

Observables

You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:

var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }

console.log(getN()); // 5

setN(10);

Example: You have a branch refactor that is quite different from master. You can't merge all of the commits, or even every hunk in any single commit or master will break, but you have made a lot of improvements there that you would like to bring over to master.

Note: This will not preserve the original change authors. Only use if necessary, or if you don't mind losing that information, or if you are only merging your own work.

On master:

> git co -b temp
@martinandersen3d
martinandersen3d / debug.php
Created May 31, 2018 00:29 — forked from eddieajau/debug.php
Printing a clean debug backtrace in PHP.
// PHP < 5.3.6
foreach (debug_backtrace() as $trace)
{
echo sprintf("\n%s:%s %s::%s", $trace['file'], $trace['line'], $trace['class'], $trace['function']);
}
die;
// PHP >= 5.3.6
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
die;
@martinandersen3d
martinandersen3d / usefull_commands.sh
Created June 25, 2018 14:09 — forked from carbontwelve/usefull_commands.sh
Running xdebug in the console, for debugging Laravel artisan commands. Useful as I keep forgetting this one...
# Running xdebug in the console, for debugging Laravel artisan commands. Useful as I keep forgetting this one...
php -dxdebug.remote_autostart artisan
#Running phpcs for 5.3:
phpcs -pv --standards= --runtime-set testVersion 5.3 --ignore=*/public/*,*.js,*.css,*/tests/*,*/views/training/* .
@martinandersen3d
martinandersen3d / xdebug
Created June 26, 2018 22:52 — forked from IngmarBoddington/xdebug
Xdebug ini settings, functions and general use.
Enable tracing example:
zend_extension="/usr/lib/php5/20090626+lfs/xdebug.so"
xdebug.auto_trace=1
xdebug.trace_output_dir="/tmp/xdebug/"
xdebug.collect_params=4
xdebug.collect_return=1
xdebug.trace_options=1
xdebug.show_local_vars=1
@martinandersen3d
martinandersen3d / String.pluralization.js
Created April 24, 2019 00:04 — forked from alexdemers/String.pluralization.js
Laravel's pluralization logic in JavaScript
// replace occurences of :vars in the string.
// "This :thing is great!".format
String.prototype.format = function(replacements) {
var str = this;
for (var key in replacements) {
if (replacements.hasOwnProperty(key)) {
str = str.replace(':' + key, replacements[key]);
}
}
@martinandersen3d
martinandersen3d / axiosget.js
Created April 29, 2019 20:57 — forked from pastranastevenaz/axiosget.js
Example of an axios get request using arrow functions
var albums = [];
axios.get('https://jsonplaceholder.typicode.com/albums')
.then(response =>{
this.albums = response.data
})
.catch(error =>{
console.log(error);
})
// Add a 401 response interceptor
window.axios.interceptors.response.use(function (response) {
return response;
}, function (error) {
if (401 === error.response.status) {
swal({
title: "Session Expired",
text: "Your session has expired. Would you like to be redirected to the login page?",
type: "warning",
showCancelButton: true,
@martinandersen3d
martinandersen3d / backupToolExportInstalledprograms.sh
Created October 21, 2019 23:21
Linux mint install, Backup Tool - Backup / export list
#!/bin/bash
# Please comment if there is a oneliner.. I looked around on google without succes :-/
backupToolOutputDir='/home/m/Documents/Backups'
targetOutputDir='/media/m/Data/Dropbox/Linux/Backups/BackupTool'
sleep 0.5
# Notification in top-right corner