Skip to content

Instantly share code, notes, and snippets.

## Configure eth0
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=A4:BA:DB:37:F1:04
TYPE=Ethernet
BOOTPROTO=static
NAME="System eth0"
@gesquive
gesquive / python-git-get.py
Last active August 29, 2015 14:06
Method to dl git repos or individual files
from sh import ErrorReturnCode, git
from cStringIO import StringIO
import tarfile
def git_get(git_repo, git_branch, git_path, destination_path=".", use_compression=True, verbose=False):
git_dir = os.path.dirname(git_path)
git_file = os.path.basename(git_path)
if git_dir.replace("/", "") == git_file:
git_file = ''
if git_dir.replace("/","").strip() == "":
git_loc = git_branch
@gesquive
gesquive / python-config-args-parser.py
Last active August 29, 2015 14:14
Code snippet to parse arguments from a config file
import argparse
import ConfigParser
import sys
def main(argv=None):
# Do argv default this way, as doing it in the functional
# declaration sets it at compile time.
if argv is None:
argv = sys.argv[1]:
@gesquive
gesquive / python-get-config-path.py
Last active August 29, 2015 14:14
Code snippet to get the config location based on the XDG Base Directory Specification.
import os
def get_config_path(project_name=None, config_name=None):
'''
Gets the config location based on the XDG Base Directory Specification.
If no config is found, the home directory based path is returned.
'''
if not project_name:
project_name = os.path.basename(__file__).split('.')[0]
if not config_name:
@gesquive
gesquive / what-is-my-ip.json
Created March 22, 2015 20:05
Text based external IP locators
[
"http://whatismyip.akamai.com/",
"http://icanhazip.com",
"http://wtfismyip.com/text",
"http://whatsmyip.me/",
"http://api.ipify.org/",
"http://ip.catnapgames.com",
"http://ip.ryansanden.com",
]
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite

Keybase proof

I hereby claim:

  • I am gesquive on github.
  • I am gesquivel (https://keybase.io/gesquivel) on keybase.
  • I have a public key ASB9AOb3ILKZj7j51Ya6YNtREiujK6jd3qlBW4H3wur5Qgo

To claim this, I am signing this object:

#!/bin/sh
# original src: https://unix.stackexchange.com/a/2146/17806
# usage: authkeys-report <authorized_keys-file>
set -ue
tmp="$(mktemp -t fingerprint-authkeys.XXXXXXXX)"
trap 'rm -f "$tmp"' 0
@gesquive
gesquive / cmd.go
Created April 27, 2017 21:48
Run an external command with golang
// run a command using the shell; no need to split args
// from https://stackoverflow.com/questions/6182369/exec-a-shell-command-in-go
func runcmd(cmd string, shell bool) []byte {
if shell {
out, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
log.Fatal(err)
panic("some error found")
}
return out
@gesquive
gesquive / python-less-pager.py
Last active January 17, 2021 19:53
Use less to page output
import subprocess
import sys
import os
def output_to_pager(text):
try:
# args stolen fron git source, see `man less`
pager = subprocess.Popen(['less', '-F', '-R', '-S', '-X', '-K'],
stdin=subprocess.PIPE,
stdout=sys.stdout)