Skip to content

Instantly share code, notes, and snippets.

View gusenov's full-sized avatar
⌨️
Программирую компьютеры 💻

Аббас Гусенов gusenov

⌨️
Программирую компьютеры 💻
View GitHub Profile
@chrisroos
chrisroos / gpg-import-and-export-instructions.md
Created September 9, 2011 10:49
Instructions for exporting/importing (backup/restore) GPG keys

Every so often I have to restore my gpg keys and I'm never sure how best to do it. So, I've spent some time playing around with the various ways to export/import (backup/restore) keys.

Method 1

Backup the public and secret keyrings and trust database

cp ~/.gnupg/pubring.gpg /path/to/backups/
cp ~/.gnupg/secring.gpg /path/to/backups/
cp ~/.gnupg/trustdb.gpg /path/to/backups/

or, instead of backing up trustdb...

@ciastek
ciastek / lxc-attach substitute
Created January 22, 2014 03:30
Run script in LXC container, non-interactive
# create container with key authentication
sudo lxc-create -t ubuntu -n test -- -S /root/.ssh/id_rsa.pub
sudo lxc-start -n test -d
sudo lxc-wait -n test -s RUNNING
# enable passwordless sudo for ubuntu user
chroot /var/lib/lxc/test/rootfs sh -c "echo 'ubuntu ALL=NOPASSWD:ALL' > /etc/sudoers.d/ubuntu; chmod 440 /etc/sudoers.d/ubuntu"
# now you can run commands in container, example: install avahi-daemon
ssh `cat /var/lib/misc/dnsmasq.leases | grep --word-regexp test | awk '{print $3}'` -l ubuntu -o "StrictHostKeyChecking no" sudo apt-get install -y avahi-daemon
@leroix
leroix / check-remote-sync.sh
Created February 5, 2014 18:15
Git: check if a branch is sync'd with a branch of the same name in a remote repo e.g. `check-remote-sync development origin`. Returns nothing if in sync.
#!/bin/bash
LOCAL_BRANCH=$1
REMOTE_BRANCH="${2:-origin}/$1"
if [ x"$(git rev-parse $LOCAL_BRANCH)" != x"$(git rev-parse $REMOTE_BRANCH)" ]
then
echo "$LOCAL_BRANCH is not in sync with $REMOTE_BRANCH. You may want to rebase or push first."
fi
@kimus
kimus / ufw.md
Created March 2, 2014 22:46
NAT and FORWARD with Ubuntu’s ufw firewall

UFW

I use Ubuntu’s Uncomplicated firewall because it is available on Ubuntu and it's very simple.

Install UFW

if ufw is not installed by default be sure to install it first.

chmod cheat sheet
PERMISSION COMMAND
U G W
_____________________________________
|rwx rwx rwx chmod 777 <filename> |
|_____________________________________|
|rwx rwx r-x chmod 775 <filename> |
|_____________________________________|
@psayre23
psayre23 / gist:c30a821239f4818b0709
Last active June 27, 2024 17:48
Runtime Complexity of Java Collections
Below are the Big O performance of common functions of different Java Collections.
List | Add | Remove | Get | Contains | Next | Data Structure
---------------------|------|--------|------|----------|------|---------------
ArrayList | O(1) | O(n) | O(1) | O(n) | O(1) | Array
LinkedList | O(1) | O(1) | O(n) | O(n) | O(1) | Linked List
CopyOnWriteArrayList | O(n) | O(n) | O(1) | O(n) | O(1) | Array
@chrisroos
chrisroos / README.md
Created September 11, 2015 11:10
Using pcregrep to extract reference links from Markdown documents

Using grep (well, pcregrep) to display the labels of reference style links in a Markdown document:

$ pcregrep --only-matching=1 \  # Only display the match from group 1
  "\[.*?\](\[.*?\])" \          # Find [text][label] reference style links
  /path/to/document.md | \      # Path to the markdown document
  sort                          # Optionally sort the output

I had the regexp working in grep but couldn't capture just the group I was interested in. This Stack Overflow answer suggested pcregrep.

@scottoffen
scottoffen / clipboard-example.html
Last active April 13, 2022 08:38
JavaScript Copy To Clipboard Example
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Copy To Clipboard Example</title>
</head>
<body>
<input id="txtToCopy" type="text">
<button id="btnCopy">Copy!</button>
@erikbern
erikbern / use_pfx_with_requests.py
Last active June 5, 2024 12:18
How to use a .pfx file with Python requests – also works with .p12 files
import contextlib
import OpenSSL.crypto
import os
import requests
import ssl
import tempfile
@contextlib.contextmanager
def pfx_to_pem(pfx_path, pfx_password):
''' Decrypts the .pfx file to be used with requests. '''
@libitte
libitte / gist:cbde168d26bc5faf9bf9fef648091b42
Last active November 11, 2022 19:30
FIX warning: ignoring broken ref refs/remotes/origin/HEAD

warning: ignoring broken ref refs/remotes/origin/HEAD


➜   ✗ g symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/develop
➜   ✗ g fetch --prune
➜   ✗ g gc