Skip to content

Instantly share code, notes, and snippets.

View BlogBlocks's full-sized avatar

Jack Northrup BlogBlocks

View GitHub Profile
@BlogBlocks
BlogBlocks / !ocate center
Last active April 24, 2018 21:44
largest center square of image
w= 1000;h=500
x=0;xy=0;y=w;yx=h
sf= abs((w-h)/2)
if w>h:x=x+sf
if w>h:y=w-sf
if w<h:xy=sf
if w <h:yx=h-sf
print (sf)
@BlogBlocks
BlogBlocks / fix-permissions.sh
Last active January 31, 2018 03:42
Error: dconf-CRITICAL **: unable to create file '~/.cache/dconf/user': Permission denied. dconf will not work properly.
#!/bin/bash
# corrects the error
# Error: dconf-CRITICAL **: unable to create file '~/.cache/dconf/user': Permission denied. dconf will not work properly.
# Run fix-permissions.sh as sudo
# $1 is a variable to insert your name as owner
# Use Example:
# chmod +x fix-permissions.sh
# sudo ./fix-permissions.sh yourusername
chown $1 ~/.cache/dconf
chown $1 ~/.cache/conf
@BlogBlocks
BlogBlocks / FixWarn.sh
Last active January 31, 2018 03:34
Ubuntu Error: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-tGXmtmmBTs: Connection refused
#!/bin/bash
# ** (mousepad:540): WARNING **: Couldn't connect to accessibility bus:
# Failed to connect to socket /tmp/dbus-tGXmtmmBTs: Connection refused
# If you do not use alley -
# Add the following to ~/.bashrc:
echo "export NO_AT_BRIDGE=1" ~/.bashrc
source ~/.bashrc
@BlogBlocks
BlogBlocks / MergingSqliteDatabasesByExample.py
Created December 19, 2017 00:19
Python - Merging two Sqlite3 databases into a third by example.
import sqlite3
import time
import sqlite3
Dbase = 'test0.db'
conn = sqlite3.connect(Dbase)
c = conn.cursor()
c.execute('''
CREATE VIRTUAL TABLE IF NOT EXISTS merge
USING FTS3(file, keyword);
''')
@BlogBlocks
BlogBlocks / ScrapySider py
Created December 17, 2017 00:05
spider from Stackoverflow
#!/usr/bin/env python3
import scrapy
class MySpider(scrapy.Spider):
name = 'myspider'
start_urls = ['http://www.usfigureskating.org/leaderboard/results/2018/25073/SEGM001.html']
@BlogBlocks
BlogBlocks / ScrapySider py
Created December 17, 2017 00:05
spider from Stackoverflow
#!/usr/bin/env python3
import scrapy
class MySpider(scrapy.Spider):
name = 'myspider'
start_urls = ['http://www.usfigureskating.org/leaderboard/results/2018/25073/SEGM001.html']
@BlogBlocks
BlogBlocks / mult.py
Last active December 17, 2017 00:06
multiple keywords
x = input("What programming language do you know ?")
keywords = ["Python", "JavaScript", "Ruby"]
if any(keyword in x for keyword in keywords):
print("I know that language also !")
@BlogBlocks
BlogBlocks / jointxt.py
Last active December 19, 2017 00:22
Combines all *.txt files in a directory into one
# Combines all *.txt files in a directory into one
# NOTICE: it is saved as a .text extension.
# That is so it will not be read as a result file of a new search
import time, glob
clean=open("test.text");clean.close()
#outfilename = 'all_' + str((int(time.time()))) + ".txt"
outfilename = "test.text"
filenames = glob.glob('*.txt')
with open(outfilename, 'wb') as outfile:
@BlogBlocks
BlogBlocks / GDownload.py
Last active December 19, 2017 00:22
Google Drive Downloader
# USAGE EXAMPLE:
# From gogle link - https://drive.google.com/file/d/1J18blSZ5ic_SoEOc7pGBz_Sr4RIZJUuK/view?usp=sharing
# 1J18blSZ5ic_SoEOc7pGBz_Sr4RIZJUuK is the file ID
# python GDownload.py 1J18blSZ5ic_SoEOc7pGBz_Sr4RIZJUuK google.db
import requests
import sys
def download_file_from_google_drive(id, destination):
URL = "https://docs.google.com/uc?export=download"
session = requests.Session()
import sys
"""
Displays a range of lines in a file
USAGE:
"""
filename = sys.argv[1]
start = int(sys.argv[2])
end = int(sys.argv[3])
f = open(filename, "r")
lines = f.readlines()