Skip to content

Instantly share code, notes, and snippets.

Avatar

Adrian adrian-enspired

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

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.
View sql.md

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;
View array_dig.php
<?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
*/
View xy.md

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

           foo
          ------
          foo_id

    foox          fooy
   ------        ------
 foo_id foo_id
View super.php
<?php
class Wrong {
public function getX() {
return $_GET['x'] ?? 'default x';
}
}
class Right {
View entity-vs-storage.php
<?php
class Role {
protected $name;
protected $permissions = [];
public function __construct(string $name, array $permissions) {
$this->name = $name;
$this->permissions = $permissions;
View ramdisk.sh
#!/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 Mar 3, 2017
riot mixin for converting opts.class to a list.
View classlister.mixin.js
(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));
},