Skip to content

Instantly share code, notes, and snippets.

@shrkw
shrkw / db.sqlite3
Created October 28, 2013 16:06
ForeingKey experiments on SQLAlchemy. It seems following 2 python codes are equivalent. According to my experiments, if you want to have `relationship`, you need to use explicitly any `foreign` by `ForeignKey` schema or `foreign` annotation. Anyway you can get the power of `relationship` with or without the foreign key constraints.
CREATE TABLE addresses (
id INTEGER NOT NULL,
email VARCHAR NOT NULL,
owner_id INTEGER,
PRIMARY KEY (id)
);
CREATE TABLE users (
id INTEGER NOT NULL,
name VARCHAR NOT NULL,
PRIMARY KEY (id)
@wowo
wowo / IsolatedTestsTrait.php
Last active September 11, 2020 08:05
IsolatedTestsTrait helps with running functional/integration tests in isolation, with same start state for each test. It's also optimized, keeping in mind performance concerns.
<?php
namespace Acme\Example\Tests;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSqliteDriver;
require_once(__DIR__ . IsolatedTestsTrait::$kernelRootDir . '/AppKernel.php');
@hofmannsven
hofmannsven / README.md
Last active April 30, 2025 15:25
Git CLI Cheatsheet
@scy
scy / opening-and-closing-an-ssh-tunnel-in-a-shell-script-the-smart-way.md
Last active May 7, 2025 21:41
Opening and closing an SSH tunnel in a shell script the smart way

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@henriquemoody
henriquemoody / http-status-codes.php
Last active March 7, 2025 15:17
List of HTTP status codes in PHP
<?php
/**
* Content from http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
*
* You may also want a list of unofficial codes:
*
* 103 => 'Checkpoint',
* 218 => 'This is fine', // Apache Web Server
* 419 => 'Page Expired', // Laravel Framework
@grenade
grenade / 01-generate-ed25519-ssh-key.sh
Last active April 11, 2025 19:59
generate ed25519 ssh and gpg/pgp keys and set file permissions for ssh keys and config
#!/bin/bash
mkdir -p ~/.ssh
# generate new personal ed25519 ssh keys
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C "rob thijssen <[email protected]>"
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_robtn -C "rob thijssen <[email protected]>"
# generate new host cert authority (host_ca) ed25519 ssh key
# used for signing host keys and creating host certs
@damphat
damphat / apt-rdepends-tree
Last active April 1, 2025 18:24
debian dependency tree
#! /bin/bash
# Description: show dependency tree
# Author: damphat
if [ $# != 1 ]; then
echo 'Usage: apt-rdepends-tree <package>'
echo 'Required packages: apt-rdepends'
exit 1
fi
@flomotlik
flomotlik / gist:6212725
Last active November 13, 2017 18:46
Wget Curl comparison and our Approach

We have changed our check_url implementation from curl to wget for three reasons

  1. It gives us the ability to retry on connection refused. Compare the command we used previously with curl:
curl -sSfL --retry 3 URL

to the current one:

@willurd
willurd / web-servers.md
Last active May 16, 2025 23:15
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
{{#linkTo 'contact' contact tagName="tr"}}
<td>{{name}}</td>
<td><button {{action destroy contact bubbles=false}}>Destroy!</button></td>
<td>{{#linkTo 'somewhere else' foo}}something{{/linkTo}}</td>
{{/linkTo}}