Skip to content

Instantly share code, notes, and snippets.

@wiyoe
wiyoe / git.txt
Last active July 22, 2019 06:35
Git tips and tricks
alias gs='git status'
alias gc='git checkout'
alias gl='git pull origin $(git rev-parse --abbrev-ref HEAD)'
alias gp='git push origin $(git rev-parse --abbrev-ref HEAD)'
git checkout - => Switch to previous branch.
alias pb='git checkout -'
git branch -m {{new_branch_name}} => Rename branch.
git reset --hard HEAD => Cancel Staged changes (before committing)
@wiyoe
wiyoe / parsing.js
Created September 24, 2018 07:45
Parsing URL string with lodash
_.chain(rawUrl)
.replace('?', '') // a=b454&c=dhjjh&f=g6hksdfjlksd
.split('&') // ["a=b454","c=dhjjh","f=g6hksdfjlksd"]
.map(_.partial(_.split, _, '=', 2)) // [["a","b454"],["c","dhjjh"],["f","g6hksdfjlksd"]]
.fromPairs() // {"a":"b454","c":"dhjjh","f":"g6hksdfjlksd"}
.value()
@wiyoe
wiyoe / changeState.js
Last active August 13, 2018 13:05
Angularjs change state param without reload.
$state.transitionTo(to, {'tab': 'comments'}, { location: true, inherit: true, notify: false, reload: false});
@wiyoe
wiyoe / loading-spin.html
Created June 19, 2018 14:37
CSS button loading spin.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style>
* {
@wiyoe
wiyoe / shortif.js
Created June 13, 2018 06:53
Javascript Short If Structure
render.page ? (render.page - 1 < 0 ? 0 : render.page - 1) : 0
@wiyoe
wiyoe / username.js
Created June 1, 2018 07:47
Javascript username input selector.
document.querySelector("input[type='password']").parentElement.parentElement.querySelector("input[type='text']").value;
document.querySelector("input[type='password']").parentElement.parentElement.querySelector("input[type='email']").value;
@wiyoe
wiyoe / closure.php
Created May 21, 2018 11:03
PHP Closure by Reference
// Set counter
$i = 0;
// Increase counter within the scope
// of the function
$closure = function () use ($i){ $i++; };
// Run the function
$closure();
// The global count hasn’t changed
echo $i; // Returns 0
@wiyoe
wiyoe / ng-sharing.js
Last active May 10, 2018 07:47
AngularJS Sharing Data Between Directives
//http://plnkr.co/edit/ZZOjr2?p=preview
//https://daveceddia.com/sharing-data-between-controllers-best-practice-use-a-service/
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, dataService) {
$scope.name = 'World';
//set up the items.
angular.copy([ { name: 'test'} , { name: 'foo' } ], dataService.items);
});
@wiyoe
wiyoe / enums.js
Last active May 3, 2018 07:14
Javascript freeze, enumaration constants.
const DaysEnum = {"MONDAY":1, "TUESDAY":2, "WEDNESDAY":3};
Object.freeze(DaysEnum);
@wiyoe
wiyoe / margins-paddings.scss
Last active April 26, 2018 12:56
Sass default margins and paddings generator.
$size: 8;
$margins: (mb: margin-bottom, mt: margin-top, mr: margin-right, ml: margin-left);
@each $key, $item in $margins {
@for $i from 1 through $size {
.#{$key}-#{$i} {
#{$item}: (2em * $i) / 4;
}
}