Skip to content

Instantly share code, notes, and snippets.

@joseluisq
joseluisq / nginx.conf
Created June 17, 2016 03:10 — forked from jrom/nginx.conf
nginx hack for multiple conditions
if ($request_uri = /) {
set $test A;
}
if ($host ~* teambox.com) {
set $test "${test}B";
}
if ($http_cookie !~* "auth_token") {
set $test "${test}C";
@joseluisq
joseluisq / .gitconfig
Created July 11, 2016 21:34 — forked from robmiller/.gitconfig
Some useful Git aliases that I use every day
#
# Working with branches
#
# Get the current branch name (not so useful in itself, but used in
# other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track
# the upstream branch
publish = "!git push -u origin $(git branch-name)"
@joseluisq
joseluisq / transfer.fish
Created August 16, 2016 02:45 — forked from nl5887/transfer.fish
Bash and zsh alias for transfer.sh. Transfers files and directories to transfer.sh.
function transfer
if test (count $argv) -eq 0
echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
return 1
end
## get temporarily filename, output is written to this file show progress can be showed
set tmpfile ( mktemp -t transferXXX )
## upload stdin or file
sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
@joseluisq
joseluisq / numberformat.js
Created August 29, 2016 14:48
number_format(number, decimals, decPoint, thousandsSep) in JavaScript, known from PHP. It formats a number to a string with grouped thousands, with custom seperator and custom decimal point
function number_format(number, decimals, decPoint, thousandsSep){
decimals = decimals || 0;
number = parseFloat(number);
if(!decPoint || !thousandsSep){
decPoint = '.';
thousandsSep = ',';
}
var roundedNumber = Math.round( Math.abs( number ) * ('1e' + decimals) ) + '';
@joseluisq
joseluisq / KeyGenerateCommand.php
Created August 31, 2016 22:19 — forked from krisanalfa/KeyGenerateCommand.php
Lumen Key Generator Commands
<?php
namespace App\Console\Commands;
use Illuminate\Support\Str;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
class KeyGenerateCommand extends Command
{
@joseluisq
joseluisq / 1. temp.php (before fixing)
Created February 15, 2017 18:00 — forked from gsherwood/1. temp.php (before fixing)
PHPCS/PHPCBF PSR-2 auto-formatting example
<?php
namespace Vendor\Package;
use FooInterface; use BarClass as Bar; use OtherVendor\OtherPackage\BazClass;
class Foo extends Bar implements FooInterface {
public function sampleFunction($a,$b=null) {
if ($a === $b) { bar();
} else if ($a>$b) {
$foo->bar( $arg1 ); }
else {
BazClass::bar($arg2,$arg3 );
@joseluisq
joseluisq / slugify.js
Last active August 3, 2023 17:21 — forked from mathewbyrne/slugify.js
Javascript Slugify
function slugify (text, ampersand = 'and') {
const a = 'àáäâèéëêìíïîòóöôùúüûñçßÿỳýœæŕśńṕẃǵǹḿǘẍźḧ'
const b = 'aaaaeeeeiiiioooouuuuncsyyyoarsnpwgnmuxzh'
const p = new RegExp(a.split('').join('|'), 'g')
return text.toString().toLowerCase()
.replace(/[\s_]+/g, '-') // Replace whitespace and underscore with single hyphen
.replace(p, c =>
b.charAt(a.indexOf(c))) // Replace special chars
.replace(/&/g, `-${ampersand}-`) // Replace ampersand with custom word
@joseluisq
joseluisq / random.md
Created November 9, 2017 12:55 — forked from joepie91/random.md
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's