Skip to content

Instantly share code, notes, and snippets.

View dbrant's full-sized avatar
🍣
Kickin' it

Dmitry Brant dbrant

🍣
Kickin' it
View GitHub Profile
@dbrant
dbrant / fix_quotes.sql
Created October 27, 2021 01:22
Fix incorrectly encoded quotes and apostrophes in SQL database
UPDATE wp_posts SET post_content = REPLACE(post_content, '“', '“');
UPDATE wp_posts SET post_content = REPLACE(post_content, '”', '”');
UPDATE wp_posts SET post_content = REPLACE(post_content, '’', '’');
UPDATE wp_posts SET post_content = REPLACE(post_content, '‘', '‘');
UPDATE wp_posts SET post_content = REPLACE(post_content, '—', '–');
UPDATE wp_posts SET post_content = REPLACE(post_content, '–', '—');
UPDATE wp_posts SET post_content = REPLACE(post_content, '•', '-');
UPDATE wp_posts SET post_content = REPLACE(post_content, '…', '…');
UPDATE wp_posts SET post_content = REPLACE(post_content, '…', '…');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'Â', ' ');
@dbrant
dbrant / uploadfiles.py
Created January 8, 2020 21:26
Upload a list of files to Google Drive
import os
import sys
import pickle
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
directoryIndexMap = {}
@dbrant
dbrant / sendemail.py
Created January 8, 2020 21:19
Send email via python
import smtplib
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("account@example.com", password)
msg = "To: destination@example.com\n"
msg += "From: source@example.com\n"
msg += "Subject: "
@dbrant
dbrant / arcDestruct.bat
Last active May 22, 2019 22:31
Windows Batch file for auto-extracting ARC archives into their own directory.
REM You can put this batch file on your Desktop, and drag-and-drop ARC files into it!
REM It will automatically create a folder with the same name as the ARC file, extract the files into it, and delete the original ARC file.
mkdir "%~p1\%~n1"
move %1 "%~p1\%~n1"
cd "%~p1\%~n1"
E:\cygwin\bin\arc.exe x "%~p1\%~n1\%~n1.arc"
del "%~p1\%~n1\%~n1.arc"
{
"batchcomplete": "",
"query": {
"notifications": {
"list": [
{
"wiki": "enwiki",
"id": "73770596",
"type": "edit-user-talk",
"category": "edit-user-talk",
@dbrant
dbrant / pi_gpio_sample.py
Created March 19, 2016 17:20
GPIO sample for Raspberry Pi
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(4,GPIO.OUT)
GPIO.setup(23,GPIO.OUT)
GPIO.setup(25,GPIO.OUT)
index = 0
while True:
@dbrant
dbrant / CatchNameNotFoundException.jaja
Created February 19, 2016 03:38
Sketch of catching exception when WebView is being updated.
@Override
protected void onStart() {
try {
super.onStart();
} catch (Throwable t) {
if (ThrowableUtil.throwableContainsException(t, PackageManager.NameNotFoundException.class)) {
// This can happen when the system updates the WebView component. There's a
// brief window of time when the old WebView is uninstalled from the package
// manager, and the new one is not yet installed, so it literally doesn't exist.
@dbrant
dbrant / ImagePipelineStreamGetter.java
Last active February 3, 2016 03:56
Get stream from Fresco image pipeline.
private abstract class ImagePipelineStreamGetter {
private String imageUrl;
public ImagePipelineStreamGetter(String imageUrl) {
this.imageUrl = imageUrl;
}
public abstract void onSuccess(InputStream stream);
public abstract void onError(Throwable t);
@dbrant
dbrant / symbology
Last active July 21, 2020 02:04
Useful symbols
ligature: ff fi fl ffi ffl
hyphen: ‐
non-breaking hyphen: ‑
minus sign: −
figure dash: ‒
en dash: –
em dash: —
horizontal bar: ―