Skip to content

Instantly share code, notes, and snippets.

@alexshtf
alexshtf / constexpr_sqrt.cpp
Last active June 7, 2023 11:19
Constexpr version of c++ square root (for doubles)
#include <limits>
namespace Detail
{
double constexpr sqrtNewtonRaphson(double x, double curr, double prev)
{
return curr == prev
? curr
: sqrtNewtonRaphson(x, 0.5 * (curr + x / curr), curr);
}
@lttlrck
lttlrck / gist:9628955
Created March 18, 2014 20:34
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@Romain-Geissler
Romain-Geissler / test.sh
Created December 11, 2012 20:54
SSH connection multiplexing in sh (credentials asked only once with several ssh/scp commands).
#!/bin/sh
set -e;
BASE_DIRECTORY="$(cd "$(dirname "$0")"&&pwd)"
SSH_SOCKET="${BASE_DIRECTORY}"/%r.%h.%p.ssh_socket
SSH_HOST=localhost
#Exit ssh master connection when the script exits or is killed.
trap "ssh -q -o ControlMaster=no -o ControlPath=${SSH_SOCKET} -O exit ${SSH_HOST};" SIGINT SIGTERM EXIT;
@bmc
bmc / stack.sh
Created October 28, 2011 21:04
A stack implementation, in bash
# A stack, using bash arrays.
# ---------------------------------------------------------------------------
# Create a new stack.
#
# Usage: stack_new name
#
# Example: stack_new x
function stack_new
{