Skip to content

Instantly share code, notes, and snippets.

@wiyoe
wiyoe / each.scss
Created April 25, 2018 11:05
Bootstrap buttons overriding with sass each.
$buttons: (
info: blue,
success: green,
warning: yellow,
danger: red
);
.btn{
@each $btn-type, $btn-colour in $buttons {
&.btn-#{$btn-type} {
@wiyoe
wiyoe / overload.js
Created April 17, 2018 06:59
Javascript overloading.
function overloadMethod(object, name, fn){
if(!object._overload){
object._overload = {};
}
if(!object._overload[name]){
object._overload[name] = {};
}
if(!object._overload[name][fn.length]){
@wiyoe
wiyoe / call.js
Created April 17, 2018 06:57
The apply, call, and bind methods
var user = {
name: "Rahul Mhatre",
whatIsYourName: function() {
console.log(this.name);
}
};
user.whatIsYourName(); // Output: "Rahul Mhatre",
var user2 = {
name: "Neha Sampat"
@wiyoe
wiyoe / method-chaining.php
Created April 10, 2018 11:31
PHP method chaining ($this)
<?php
class fakeString
{
private $str;
function __construct($str = null)
{
$this->str = $str;
}
@wiyoe
wiyoe / laravel-translations.php
Created April 9, 2018 11:29
Laravel Translations Array to JSON
public function getTranslations()
{
$dir = '../resources/lang/en';
$files = array_diff(scandir($dir), array('.', '..'));
$callback = function($element) {
return explode(".", $element)[0];
};
@wiyoe
wiyoe / loader.css
Created March 30, 2018 13:38
CSS Loader
.loader {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}
/* Static Shape */
@wiyoe
wiyoe / iife.js
Last active March 30, 2018 12:48
Jquery IIFE
(function($) {
$(document).on('ready', function() {
$('.back-to-top').on('click', function(e) {
e.preventDefault();
$("html, body").animate({
scrollTop: 0
}, 700);
});
@wiyoe
wiyoe / singleton.php
Created March 30, 2018 07:15
PHP singleton
class Manager
{
private static $instance;
public static function get_instance()
{
if (!isset(self::$instance)) {
$class_name = __CLASS__;
self::$instance = new $class_name;
@wiyoe
wiyoe / constant.php
Created March 30, 2018 06:54
PHP constants
class A
{
const foo = 'bar';
public function getConstant( $const )
{
return constant('self::' . $const);
}
}
@wiyoe
wiyoe / curl.txt
Created March 22, 2018 14:30
Curl options
curl -X POST "https://magento.host/index.php/rest/V1/integration/customer/token" \
-H "Content-Type:application/json" \
-d "{"username":"customer1@example.com", "password":"customer1pw"}"