Skip to content

Instantly share code, notes, and snippets.

@StuffbyYuki
StuffbyYuki / SQL:Oracle - list all schema names
Last active April 27, 2020 00:39
SQL:Oracle - list all schema names
select username as schema_name
from sys.all_users
order by username;
@StuffbyYuki
StuffbyYuki / SQL:Oracle - Show the number of columns in a table
Last active April 27, 2020 00:40
SQL:Oracle - Show the number of columns in a table
select count(*)
from all_tab_columns
where owner = 'SOME_USER' --put yours
and table_name = 'SOME_TABLE'; --put yours in upper case. lower(table_name) for lower case
/*
e.g.
select count(*)
from all_tab_columns
where owner = 'IRIRPT'
@StuffbyYuki
StuffbyYuki / SQL:Oracle - Query to list column names in a table
Last active April 27, 2020 00:40
SQL:Oracle - Query to list column names in a table
DESCRIBE YourTableHere;
@StuffbyYuki
StuffbyYuki / JS - Get random element from the specified array
Last active April 27, 2020 00:38
JS - Get random element from the specified array
//You specify an array of item in the argument
function random_item(items) {
return items[Math.floor(Math.random()*items.length)];
};
@StuffbyYuki
StuffbyYuki / JS - Get max or min value in an array
Last active April 27, 2020 00:40
JS - Get max or min value in an array
//The follwoing will work
var nums = [1, 2, 3]
Math.min.apply(Math, nums) // 1
Math.max.apply(Math, nums) // 3
Math.min.apply(null, nums) // 1
Math.max.apply(null, nums) // 3
//This doesn't work
var nums = [1, 2, 3]
Math.min(nums) // NaN
@StuffbyYuki
StuffbyYuki / Python:Matplotlib - Add labels on bar chart
Created April 27, 2020 00:41
Python:Matplotlib - Add labels on bar chart
def autolabel(rects, xpos='center'):
"""
Attach a text label above each bar in *rects*, displaying its height.
*xpos* indicates which side to place the text w.r.t. the center of
the bar. It can be one of the following {'center', 'right', 'left'}.
"""
xpos = xpos.lower() # normalize the case of the parameter
ha = {'center': 'center', 'right': 'left', 'left': 'right'}
@StuffbyYuki
StuffbyYuki / Python:Git - Command to set and activate virtual environment
Last active June 23, 2021 04:46
Python:Git - Command to set and active virtual environment
#Refer to the documentaions for details -> https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
#Mac
python3 -m venv env
source env/bin/activate
#Windows
python -m venv env
.\env\Scripts\activate
@StuffbyYuki
StuffbyYuki / Python:Git - Command to write & read from a requirements.txt file
Created April 27, 2020 00:49
Python:Git - Command to write & read from a requirements.txt file
#Do when your virtual environment is active
#source env/bin/activate
#pip install YOURPACKAGE
pip freeze > requirements.txt #Write installed pip packages to a text tile
pip install -r requirement.txt #install all packages in requirement.txt
@StuffbyYuki
StuffbyYuki / VScode - Keybindings, shortcut to toggle between editor and terminal
Created April 30, 2020 02:25
VScode - Keybindings, shortcut to toggle between editor and terminal
// Toggle between terminal and editor focus
{ "key": "ctrl+`", "command": "workbench.action.terminal.focus"},
{ "key": "ctrl+`", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}
@StuffbyYuki
StuffbyYuki / Python: Numpy - trim mean function
Created May 22, 2020 01:47
Python: Numpy - trim mean function
import numpy as np
def trimmean(arr, percent):
n = len(arr)
k = int(round(n*(float(percent)/100)/2))
return np.mean(arr[k+1:n-k])