Skip to content

Instantly share code, notes, and snippets.

View james4388's full-sized avatar
🎯
Focusing

Nhu H Trinh james4388

🎯
Focusing
View GitHub Profile
def helloworld():
print('Hello world!')
import __hello__
@james4388
james4388 / jquery.plugin.js
Last active October 5, 2017 17:37
jQuery Plugin boilerplate
;(function($, window, document, undefined) {
"use strict";
// Default options
var pluginName = "pluginName", //plugin name that will be use in $(element).pluginName
defaults = {
// Options
// Events
};
@james4388
james4388 / gist:203aa2aa549133226e5fe31eea1dec99
Last active April 24, 2018 21:57
Excel ISO-8601 convert
=DATEVALUE(LEFT(A1,10))
+ TIMEVALUE(MID(A1,12,8))
+ IF("Z"=MID(A1,20,LEN(A1)-19),0,(INT(MID(A1,20,LEN(A1)-19)/100)*60+MOD(MID(A1,20,LEN(A1)-19),100))/1440)
# Credit http://www.kddart.org/help/kdsmart/html/excel-support.html
@james4388
james4388 / mjpeg_stream.py
Created June 24, 2018 05:10
mjpeg streaming using aiohttp and opencv
import asyncio
import cv2
from aiohttp import web, MultipartWriter
async def mjpeg_handler(request):
boundary = "boundarydonotcross"
response = web.StreamResponse(status=200, reason='OK', headers={
'Content-Type': 'multipart/x-mixed-replace; '
'boundary=--%s' % boundary,
@james4388
james4388 / mjpeg_stream_multipart_writer.py
Last active December 26, 2023 04:19
MJPEG stream using aiohttp, opencv, multipartwriter
import asyncio
import cv2
from aiohttp import web, MultipartWriter
async def mjpeg_handler(request):
boundary = "boundarydonotcross"
response = web.StreamResponse(status=200, reason='OK', headers={
'Content-Type': 'multipart/x-mixed-replace; '
'boundary=--%s' % boundary,
@james4388
james4388 / opencv_cmake.sh
Created June 25, 2018 19:03
OpenCV Cmake
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D PYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON_INCLUDE_DIR2=$(python3 -c "from os.path import dirname; from distutils.sysconfig import get_config_h_filename; print(dirname(get_config_h_filename()))") \
-D PYTHON_LIBRARY=$(python3 -c "from distutils.sysconfig import get_config_var;from os.path import dirname,join ; print(join(dirname(get_config_var('LIBPC')),get_config_var('LDLIBRARY')))") \
-D PYTHON3_NUMPY_INCLUDE_DIRS=$(python3 -c "import numpy; print(numpy.get_include())") \
-D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-D BUILD_opencv_python2=OFF \
@james4388
james4388 / getcolor.py
Created August 8, 2018 01:10 — forked from zollinger/getcolor.py
Simple way to get dominant colors from an image in Python
import Image, ImageDraw
def get_colors(infile, outfile, numcolors=10, swatchsize=20, resize=150):
image = Image.open(infile)
image = image.resize((resize, resize))
result = image.convert('P', palette=Image.ADAPTIVE, colors=numcolors)
result.putalpha(0)
colors = result.getcolors(resize*resize)
@james4388
james4388 / node-axios-cookie.js
Created January 11, 2019 21:38
Node Axios api test with django, cookie, session, csrf token support.
@james4388
james4388 / total_memory_usage.py
Created June 2, 2019 06:38
Approx. calculate memory ussage by object in Python
from __future__ import print_function
from sys import getsizeof, stderr
from itertools import chain
from collections import deque
try:
from reprlib import repr
except ImportError:
pass
def total_size(o, handlers={}, verbose=False):
@james4388
james4388 / CSVexport.js
Created June 7, 2019 22:28
Generate CSV with javascript
function csvBlob(rows, export_bom) {
const BOM = '\ufeff'; // Utf-8 Bytes order mark
return new Blob([(export_bom ? BOM : '') + rows.map(function(row) {
return row.map(function(col) {
return ['"', col.replace(/"/gi, '""'), '"'].join('');
}).join(',')
}).join('\n')], {type: 'text/csv;charset=utf-8;'});
}
const blob = csvBlob(temp1);