Skip to content

Instantly share code, notes, and snippets.

@thm1118
thm1118 / bulk_alter_role
Last active June 8, 2018 19:36
bulk alter role of postgreSQL's database or table or view .etc
REASSIGN OWNED BY old_role [, ...] TO new_role
@thm1118
thm1118 / what-forces-layout.md
Created June 7, 2018 08:11 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
// transform cropper dataURI output to a Blob which Dropzone accepts
function dataURItoBlob(dataURI) {
var byteString = atob(dataURI.split(',')[1]);
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ab], { type: 'image/jpeg' });
}
@thm1118
thm1118 / action3_as_system_app.md
Created February 14, 2017 11:03 — forked from chrislacy/action3_as_system_app.md
Installing Action Launcher 3 as a system app via ADB

DISCLAIMER: Follow these instructions entirely at your own risk. I, nor my company (Digital Ashes PTY LTD) take any responsibility whatsoever for any damage done to any device/property that occurs as a result of following these instructions.

The following steps describe how to install Action Launcher 3 on a rooted device as a system app, so that you will be able to enable Action Launcher 3's Google Now integration.

Prerequisites

  1. A rooted device (Google if you need help here).
  2. A computer with [ADB][0] installed, and a working knowledge of ADB.
  3. A copy of an Action Launcher 3 APK on your computer. [APKMirror.com][1] is a good place to grab a copy from. All you're doing here is setting Action 3 as a system app, so any version of the app will work. From there, the Action 3 will update via the Play Store like a typical pre-installed app (such as Gmail or YouTube).
@thm1118
thm1118 / test_distance_of_vectorize.py
Last active July 15, 2016 13:04
测试向量不同距离算法。以sklearn和scipy提供的算法测试
# -*- coding: utf-8 -*-
"""
使用sklearn 提供的距离函数测试,对 'euclidean', 'l2', 'l1', 'manhattan', 'cityblock',
'braycurtis', 'canberra', 'chebyshev', 'correlation',
'cosine', 'dice', 'hamming', 'jaccard', 'kulsinski',
'mahalanobis', 'matching', 'minkowski', 'rogerstanimoto',
'russellrao', 'seuclidean', 'sokalmichener',
'sokalsneath', 'sqeuclidean', 'yule', "wminkowski"
pearson 等20几个度量距离算法进行逐一测试。
向量空间模型主要使用tfidf
/**
* ================== angular-ios9-uiwebview.patch.js v1.1.1 ==================
*
* This patch works around iOS9 UIWebView regression that causes infinite digest
* errors in Angular.
*
* The patch can be applied to Angular 1.2.0 – 1.4.5. Newer versions of Angular
* have the workaround baked in.
*
* To apply this patch load/bundle this file with your application and add a
# usage: `python ~/Desktop/contours.py 1994-654-12_v02.tif`
# output is to a squareless.txt file and the directory "out"
# Working well with thumbnails with 400px as their longest side - untested with other dimensions
# for i in $(ls -1 | grep tif); do python /Users/artsyinc/Documents/resistance/experiments/artwork_image_cropping/contours.py $i; done
import cv2
import numpy as np
from matplotlib import pyplot as plt
import sys
from time import time
import logging
import numpy as np
from sklearn.datasets import fetch_20newsgroups
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.decomposition import LatentDirichletAllocation
from gensim.matutils import Sparse2Corpus
#from gensim.models.ldamodel import LdaModel
from gensim.models.ldamulticore import LdaMulticore
@thm1118
thm1118 / lda.py
Last active August 29, 2015 14:16 — forked from aronwc/lda.py
""" Example using GenSim's LDA and sklearn. """
import numpy as np
from gensim import matutils
from gensim.models.ldamodel import LdaModel
from sklearn import linear_model
from sklearn.datasets import fetch_20newsgroups
from sklearn.feature_extraction.text import CountVectorizer
from pylab import *
from pprint import pprint
def arrayToList(arr):
if type(arr) == type(array([])):
return arrayToList(arr.tolist())
elif type(arr) == type([]):
return [arrayToList(a) for a in arr]
else: