Skip to content

Instantly share code, notes, and snippets.

@elifiner
elifiner / fabfile.py
Last active August 29, 2015 14:12
Fabric script to properly set up a user on a remote Ubuntu.
from crypt import crypt
from fabric.api import *
from fabric.contrib.files import append, uncomment
env.user = 'root'
env.use_ssh_config = True
def create_user(name, password):
with hide('stdout'):
run('useradd -m %s' % name)
class Restartable(object):
def __init__(self, iterable):
self._iterable = iterable
self._cache = None
def __iter__(self):
if not self._cache:
if iter(self._iterable) is iter(self._iterable):
self._cache = list(self._iterable)
else:
@elifiner
elifiner / rfuncs.py
Created July 27, 2015 11:33
Count R functions in R code
import re
import os
import fnmatch
from collections import defaultdict
def find_files(directory, pattern):
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename, pattern):
filename = os.path.join(root, basename)
get_help_section_text <- function (func, section) {
funcq <- substitute(func)
if (!is.character(func)) {
func <- deparse(funcq)
}
Rd <- utils:::.getHelpFile(help(func))
data <- tools:::.Rd_get_section(Rd, section)
result <- character()
if (length(data)) {
result <- tools:::.Rd_get_text(data)
@elifiner
elifiner / isocopy.sh
Last active November 11, 2016 22:48
Create a bootable USB stick from an ISO image on OSX, command line alternative to Unetbootin
#!/usr/bin/env bash
if [ -z $2 ]; then
echo "Create a bootable USB stick from an ISO image."
echo
echo "Usage: $0 <iso> <disk>"
echo
echo "Target disks:"
diskutil list | grep '^/dev' | grep 'external' | sed -e 's/disk/rdisk/' -e 's/:$//' -e 's/^/ /'
exit 1
fi
# creates localized version of a string using Google Translate
import re
import json
import requests
from urllib.parse import quote_plus
def translate(text, source, target):
url = 'https://translate.googleapis.com/translate_a/single?client=gtx&sl={source}&tl={target}&dt=t&q={text}'
r = requests.get(url.format(source=source, target=target, text=text))
@elifiner
elifiner / setup-ubuntu-docker
Last active May 7, 2022 04:48
Set up a bare Ubuntu box to run a Docker
#!/bin/bash
# This script should set up a bare Ubuntu box (like the one in DigitalOcean)
# with everything needed to run a Docker-based environment.
#
# To set up a fresh box, login as root and run:
#
# $ curl https://gist.githubusercontent.com/elifiner/f1e19b49bf65369b82bc9d6734abc16d/raw | sh -
USER=eli
@elifiner
elifiner / create-non-root-user.sh
Last active April 4, 2024 12:02
Create an non-root user on Ubuntu and set up sudo
#!/bin/bash
# This script will set up a non-root user on an empty Ubuntu box.
#
# Login as root and run:
#
# $ curl https://gist.githubusercontent.com/elifiner/1a5ed9cb06db1c0fc59a7426e4adc1b1/raw | sh -
USER=guru
adduser --disabled-password --gecos "" $USER
@elifiner
elifiner / setup-dnsmasq-retreat-guru.sh
Last active March 24, 2019 04:54
Set up dnsmasq for local develoment in RetreatGuru
#!/bin/sh
# This script will set up a DNS server on your OSX that will redirect all programs.test,
# bookingguru.test and rgconnect.test to the correct local IP addresses.
#
# Run it using:
#
# $ curl -s https://gist.githubusercontent.com/elifiner/a4bbe415eff43df9fa970977d1a7d278/raw?$RANDOM | sh -
TLD=test
@elifiner
elifiner / simple-database.php
Last active February 13, 2024 11:00
A simple database interface for PHP
<?php
/**
* A simple wrapper around PDO for building quick DB accessing scripts.
* Was built during the Jun 19th, 2017 data recovery fiasco at RetreatGuru.
*/
class Database {
public $db;