Skip to content

Instantly share code, notes, and snippets.

@alphamarket
alphamarket / avg-download-time.py
Created November 10, 2019 05:49
Compute average download time of webpages
#!/usr/bin/python -u
from os import popen
import commands, sys
times = []
for x in xrange(int(sys.argv[1])):
status, output = commands.getstatusoutput("curl -so /dev/null %s -w %%{time_starttransfer}" %sys.argv[2])
if(status == 0):
@alphamarket
alphamarket / change-date-time.bash
Last active October 26, 2019 09:54
Change/Restore Linux's System Date & Time
# disable NTP sync
sudo timedatectl set-ntp false
# set the date-time
sudo timedatectl set-time "2019-10-29 16:20:00"
# set the timezone
sudo timedatectl set-timezone Europe/London
@alphamarket
alphamarket / friendly_urls.markdown
Created October 16, 2019 08:14 — forked from mhriess/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@alphamarket
alphamarket / certbox.cert.bash
Created October 11, 2019 10:29
Creating HTTPS certification using certbot & nginx
#!/bin/bash
# adding certbot PPA
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
# install the certbot
sudo apt-get install certbot python-certbot-nginx
@alphamarket
alphamarket / ssh-proxy.bash
Created October 5, 2019 17:04
creating an SSH proxy over a port
function ssh-proxy() {
echo "Running ssh-proxy at local port: 9999"
ssh -D 9999 -qCN $1
}
@alphamarket
alphamarket / git-proxy.bash
Last active September 27, 2024 18:58
Creating SSH proxy and making Git connect through it
# [step 1] create a ssh-proxy
ssh -D 9999 -qCN [email protected]
# [step 2] make git connect through the ssh-proxy
# [current script only]
export GIT_SSH_COMMAND='ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"'
# OR [git global setting]
git config --global core.sshCommand 'ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"'
# OR [one-time only use]
git clone -c=core.sshCommand 'ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"' [email protected]:user/repo.git
@alphamarket
alphamarket / jquery.focus.override.coffee
Last active August 9, 2018 14:35
jQuery.focus() and move cursor at the end of input
# jQuery extensions
(($) ->
_super = { }
#
# [..] some other extensions
#
_super.focus = $.fn.focus
$.fn.focus = ->
# call out the original jQuery focus
_super.focus.apply(this, arguments)