Skip to content

Instantly share code, notes, and snippets.

View Swop's full-sized avatar
👨‍💻

Sylvain MAUDUIT Swop

👨‍💻
View GitHub Profile
@Swop
Swop / AnnotatedDescription.php
Last active May 10, 2020 21:19
Annotation reader in Symfony
<?php
namespace Foo\Annotations;
/**
*@Annotation
*/
class AnnotatedDescription
{
public $value;
@Swop
Swop / gist:5990749
Created July 13, 2013 13:38
Get MySQL global databases size
#!/bin/bash
echo "SELECT table_schema, round(sum(data_length+index_length)/1024/1024,4) AS \"Size (MB)\" FROM information_schema.tables GROUP BY table_schema;" | mysql -u root --password=XXXX
@Swop
Swop / gist:6025390
Created July 17, 2013 23:14
Recreate /dev/null on a Linux box
rm /dev/null && mknod -m 666 /dev/null c 1 3
@Swop
Swop / gist:6025403
Created July 17, 2013 23:16
RSync symmetry powaa command
rsync -Haurov {USER}@{IP}:{REMOTE_PATH} {LOCAL_PATH}
@Swop
Swop / gist:6025415
Created July 17, 2013 23:17
Simple rotate log script
#!/bin/bash
# Usage: rotate.sh filename
logfile=$1
if [ ! -f $logfile ]; then
echo "log file not found $logfile"
exit 1
fi
timestamp=`date +%Y%m%d`
@Swop
Swop / push-to-new-repo.sh
Last active June 4, 2019 11:19
Push an entire local Git repository to a new remote repository
#!/bin/bash
# The command must be called inside the Git repository to send to the new repository
# Usage: push-to-new-repo.sh TARGET_REPO_URL
remote=origin;
target_repo=$1;
nb_branches=`git branch -r | grep $remote | grep -v master | grep -v HEAD | awk '{gsub(/[^\/]+\//,"",$1); print $1}' | wc -l | sed 's/ //g'`;
echo "${nb_branches} branch(es) to push";
@Swop
Swop / gist:6025495
Created July 17, 2013 23:31
Lists crontab and authorized keys for all the machine users (inline shell version: copy/paste into the terminal)
echo "===== CRONTAB ====="; \
for user in $(getent passwd | cut -f1 -d:); do \
echo -e "\n\n==> $user:" && echo "`crontab -u $user -l `"; done; \
echo "===== SSH_KEYS ====="; \
for user in $(getent passwd | cut -f1 -d:); do \
user_home=$(getent passwd | grep -E "^$user:" | cut -f6 -d:); \
if [ -e $user_home/.ssh ]; then \
if [ -e $user_home/.ssh/authorized_keys ]; then \
echo "----- $user :"; cat $user_home/.ssh/authorized_keys; \
fi; fi; done
@Swop
Swop / gist:6025534
Created July 17, 2013 23:37
Sets a NAT redirection with IPTables (inline shell script, copy/paste into the terminal after replacing INPUT_INTERFACE, OUTPUT_INTERFACE & IP_DEST with the correct values)
echo 1 > /proc/sys/net/ipv4/ip_forward && \ # NAT redirections activation
iptables -A FORWARD -i INPUT_INTERFACE -j ACCEPT && \ # Accepts IN forward packets
iptables -A FORWARD -o OUTPUT_INTERFACE -j ACCEPT && \ # Accepts OUT forward packets
iptables -t nat -A POSTROUTING -o OUTPUT_INTERFACE -j MASQUERADE && \ # Activate masquerade
iptables -t nat -A PREROUTING -i INPUT_INTERFACE -p tcp --dport 80 -j LOG --log-level warn --log-prefix NAT: && \ # Forwarded packages are logged
iptables -t nat -A PREROUTING -i INPUT_INTERFACE -p tcp --dport 80 -j DNAT --to IP_DEST:80 # Incoming packets on port 80 of INPUT_INTERFACE are sent to IP_DEST
@Swop
Swop / gist:6025565
Created July 17, 2013 23:43
Sets a proxy on Apache
<VirtualHost *>
ServerName foo.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://bar.com/
ProxyPassReverse / http://foobar.com/
<Proxy *>
@Swop
Swop / gist:6046759
Created July 20, 2013 23:03
Set VIM as the default editor
sudo update-alternatives --set editor /usr/bin/vim.basic