Skip to content

Instantly share code, notes, and snippets.

@nhannguyen95
nhannguyen95 / restart_bluetooth.sh
Created July 6, 2019 01:57 — forked from nicolasembleton/restart_bluetooth.sh
Restart Bluetooth Daemon on Mac OS X without restarting
#!/bin/bash
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
@nhannguyen95
nhannguyen95 / docker-i-t-trivia.md
Created January 22, 2019 06:01 — forked from v0lkan/docker-i-t-trivia.md
docker run -i -t
docker run -i -t --name nodejs ubuntu:latest /bin/bash

So here, -i stands for interactive mode and -t will allocate a pseudo terminal for us.

Some more trivia about these flags.

@nhannguyen95
nhannguyen95 / iterm2-oh-my-fish.md
Last active January 20, 2019 00:16 — forked from leymannx/iterm2-oh-my-fish.md
iTerm2 Solarized Dark theme + Fish shell + oh-my-fish /// macOS High Sierra
@nhannguyen95
nhannguyen95 / The Technical Interview Cheat Sheet.md
Created September 9, 2018 09:30 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@nhannguyen95
nhannguyen95 / IndexedDB101.js
Created September 9, 2018 02:59 — forked from JamesMessinger/IndexedDB101.js
Very Simple IndexedDB Example
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Open (or create) the database
var open = indexedDB.open("MyDatabase", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
@nhannguyen95
nhannguyen95 / test_runner.py
Last active August 2, 2018 10:25
Use file storage on the local filesystem in Django unit tests, worked with Django >= 1.9
import shutil
import tempfile
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.db.models import FileField
from django.apps.apps import get_model, get_models
from django.test.runner import DiscoverRunner
@nhannguyen95
nhannguyen95 / read.py
Created June 7, 2018 12:12
HDF5 read & write
import h5py
f = h5py.File('path/to/file', 'r')
# List all groups
print('Keys: %s' % f.keys())
# Get data
key = 'random_data'
random_data = np.asarray(f[key])
@nhannguyen95
nhannguyen95 / profiling.py
Created April 16, 2018 12:03
Python profiling
import pstats, cProfile
def recip_square(i):
return 1./i**2
def approx_pi(n=10000000):
val = 0.
for k in range(1,n+1):
val += recip_square(k)
return (6 * val)**.5
import cython
cimport cython
import numpy as np
cimport numpy as np
cdef extern from "utils.h":
void print_array(double *, int)
def print_np_as_c(np.ndarray[double, ndim=2, mode="c"] arr not None):
cdef int n
from keras.models import Model
from keras.applications.vgg16 import VGG16
from keras.layers import GlobalAveragePooling2D
# Wait for downloading for the 1st time,
# the weights is saved in ~/.keras/models
vgg16 = VGG16(include_top=False, # don't include 3 fully connected layers
weights='imagenet', # use pre-trained weights, not random initialization
pooling=None) # don't apply any pooling at the last convolutional layer