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
@adrian-enspired
adrian-enspired / password-tips.md
Last active March 7, 2025 02:36
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
#!/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));
},

OK, so you have a filepath made from user input; something like

$path = __DIR__ . "/uploads/{$user_input_filename}"

#1: DO NOT DO THIS. Make up your own directory names. The user has no business picking path names on your server.

#2: Filesystem traversal is bad. If you mean for the given $user_input_filename to be inside the __DIR__ . "/uploads/ directory, take a moment to check.

@adrian-enspired
adrian-enspired / array_extend_recursive.md
Last active March 7, 2025 02:39
array_merge|replace_recursive are frustrating.

say you have two arrays, $a1 and $a2, and you want to combine them.

<?php

$a1 = [
  'a' => 'foo',
  'b' => ['bar']
];
$a2 = [
  'a' => 'bar',
@adrian-enspired
adrian-enspired / bad-config.md
Last active March 7, 2025 02:39
magic configs are bad, mmmkay?

Here's a very common pattern. People recommend it everywhere. Put your config into a separate file, and require it in your script. Awesome, right!?

Halfway. Yes, doing it is better than not. BUT now you have a bunch of invisible variables in your script! This makes for code that is hard to read and debug, and is fragile because code that directly affects your script is far away from it.

Imagine you got a warning like "undefined index 'foo' …" one day. It seems obvious now — the config file is messed up. But what if there were a ton of other stuff going on around this? What if this happens six months later (when you've completely forgotten about where $config comes from)? Even worse, what if a second config file gets included somewhere in the same scope and these invisible variables start colliding!?

BAD.config.php

<?php
$config["foo"] = "Hello, World!";