Skip to content

Instantly share code, notes, and snippets.

View adrian-enspired's full-sized avatar

Adrian adrian-enspired

View GitHub Profile
@adrian-enspired
adrian-enspired / git.config
Created September 30, 2020 13:30
Various useful git aliases
# general shortcuts
###################
# status
s = status
# update working tree
u = add -u
# commit
<?php
class SimpleRouter {
protected $routes = [];
public function add(string $route, callable $controller) : SimpleRouter {
$this->routes[$route] = $controller;
return $this;
}
@adrian-enspired
adrian-enspired / password-tips.md
Last active March 10, 2020 14:50
Password Tips

Password Tips

Choose a password that is long enough, and complex enough, to be difficult to guess. Remember, attackers use specialized software to make millions of guesses per second — it's not just one person typing guesses by hand!

USE

  • Long passwords!
  • Long passwords! Passwords should be 16 characters longer.

given

create table foo (a int, b int);
insert into foo values (1,1),(1,2),(2,1),(2,2),(2,3);

I want to order first by a=1 DESC and second by b, ASC if a=1 and DESC if a<>1.

for example,

select a,b from foo order by a=1 DESC, b ASC;
<?php
/**
* Looks up a value at given path in an array subject
*
* @param array $subject The subject
* @param string $path Delimited path of keys to follow
* @param string $delimiter Path delimiter to use (defaults to .)
* @return mixed The value at the given path if it exists; null otherwise
*/

tables foo and bar can be related via x or y.

           foo
          ------
          foo_id

    foox          fooy
   ------        ------
 foo_id foo_id
<?php
class Wrong {
public function getX() {
return $_GET['x'] ?? 'default x';
}
}
class Right {
<?php
class Role {
protected $name;
protected $permissions = [];
public function __construct(string $name, array $permissions) {
$this->name = $name;
$this->permissions = $permissions;
#!/bin/bash
#Check if path is not specified, not a full path or help requested. Print help and exit
if [ -z "$1" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$(echo "$1" | cut -c 1)" != "/" ]
then
echo "USAGE: ramdisk [PATH] [BUFFER]"
echo ""
echo " PATH: The location of the file/folder. Must be a FULL PATH"
echo "BUFFER: Specify number of Megabytes larger to make ramdisk (default 1)"
echo ""
@adrian-enspired
adrian-enspired / classlister.mixin.js
Last active March 3, 2017 18:24
riot mixin for converting opts.class to a list.
(function(riot) {
/** resets the classlist from tag options. */
var listClasses = function(tag) {
tag.classlist = tag.opts.class ? tag.opts.class.split(/\s+/) : [];
};
var mixin = {
init: function() {
listClasses(this);
this.on('before-update', function() { listClasses(this); }.bind(this));
},