Skip to content

Instantly share code, notes, and snippets.

@xtream1101
xtream1101 / Backup&RestoreRepo.md
Created June 29, 2019 12:38
Backup and restore a git repo using git bundle

Backup/archive a repo

  1. Clone the repo
git clone --mirror https://github.com/vuejs/vue
  1. cd into the cloned repo
  2. Create a bundle file in the parent directory
git bundle create ../vuejs_vue.bundle --all
@xtream1101
xtream1101 / instacart_scraper.py
Last active January 31, 2022 03:21
Instacart scraper
import json
import time
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from webdriverdownloader import GeckoDriverDownloader
@xtream1101
xtream1101 / getty.py
Last active October 3, 2018 16:01
Quick example on how to download videos off getty images using only requests
import logging
import requests
import urllib
import urllib.parse
from parsel import Selector
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
"""Sort a list of dicts using multiple keys
Also be able to have the different keys sort in different orders
"""
from pprint import pprint
unsorted_data_a = [{'title': 'Foo Beta',
'date': '2018-06-03',
'value': 5},
@xtream1101
xtream1101 / sublime.sh
Created November 25, 2017 05:25
Auto create and open sublime projects
sublime_project_template='{
"folders":
[
{
"path": "."
}
],
"file_exclude_patterns":[
"*.sublime-*"
]
@xtream1101
xtream1101 / open_dirty_git_files.sh
Created November 2, 2017 17:26
Open all git files that have been modified or are untracked in sublime (or your editor of choice)
git status -s | cut -c4- | xargs -L1 sublime
@xtream1101
xtream1101 / X's Scrapers.md
Last active August 27, 2017 20:10
Current Scrapers
@xtream1101
xtream1101 / multi_try_except_flat.py
Last active June 20, 2017 20:56
Python multiple Try/except flat design
# I know dict's have `.get()`, this example was made to break if the key is not
# there to show the use of multiple try/except's
# Yes I know that having the except and else on 1 line each does not fit with PEP8 standards.
# But when you have many of them it helps reduce the size of the file and is no harder to read
data = {'some_key': 'key value'}
key_data = None
for _ in range(1):
try:
key_data = data['someKey']
@xtream1101
xtream1101 / Try #1.sql
Created April 21, 2017 14:31
Dynamic QA query
#1
DROP FUNCTION qa_fields(character varying,character varying);
CREATE OR REPLACE FUNCTION qa_fields(schema_name VARCHAR, tbl_name VARCHAR)
-- The table def needs to be known before the function runs, but the number of fields returned is dynamic :(
-- Also need to correct names for the fields, the types will alwyas be FLOAT
RETURNS TABLE(a FLOAT, b FLOAT, c FLOAT, d FLOAT, e FLOAT, f FLOAT, g FLOAT, h FLOAT, i FLOAT, j FLOAT, k FLOAT, l FLOAT, m FLOAT, n FLOAT, o FLOAT, p FLOAT, q FLOAT, r FLOAT, s FLOAT, t FLOAT, u FLOAT, v FLOAT, w FLOAT, x FLOAT, ts DATE) AS
$func$
DECLARE field_name VARCHAR;
@xtream1101
xtream1101 / python_venv_shortcuts.sh
Last active December 6, 2016 21:46
Easy python environments
# Put this code in your .bashrc or .bash_profile
# Get Virtual Env
Color_Off="\033[0m" # Text Reset
Purple="\033[0;35m" # Purple
virtualenv_prompt() {
if [[ $VIRTUAL_ENV != "" ]]; then
venv=${VIRTUAL_ENV##*/}
# Strip out the path and just leave the env name