Skip to content

Instantly share code, notes, and snippets.

View akhsiM's full-sized avatar
🎯
Focusing

Mishka Nguyen akhsiM

🎯
Focusing
  • Australia
View GitHub Profile
const capitalize = (s) => {
if (typeof s !== 'string') return '';
return s.charAt(0).toUpperCase() + s.toLowerCase().slice(1)
}
function showMultilevelDropdownMenu(title, elementId, data, nameKey, valueKey, childrenKey) {
/*
This function can be used to create a multilevel dropdown menu.
It needs the following arguments:
- title: title of the main Dropdown Button
- elementId: Where the dropdown menu will be generated within.
- data: array of JS object, with the following attributes:
- nameKey: this attribute will be used as the displayed innerHTML/ text of the menu option
- valueKey: this attribute will be used as the "value" attribute of the menu option
/*
In JS the array.sort() function can take a COMPARE function as an argument argument. The purpose of this function is to define an alternative order.
This is useful in cases where we need to sort an array of JS objects, using a key attribute, such as "ordering".
Example:
function(a, b) {
return a - b
@akhsiM
akhsiM / django-snippets
Last active December 14, 2020 12:57
Django snippets
# Hello World
<div style="page-break-after: always; visibility: hidden"> \pagebreak </div>
-- Clear all temp tables in your space
undef current_schema;
begin
for cur_cleanup in (
select object_name
,object_type
from user_objects
where object_type = 'TABLE'
and temporary = 'Y'
from datetime import datetime, timedelta
from dateutil.tz import tzlocal
def convert_from_utc(input, offset=0, outputstr=True, tz=False):
'''
This operation accepts three arguments:
1. str input: Input with format specified below