Skip to content

Instantly share code, notes, and snippets.

View waikyaw9999's full-sized avatar
🏠
Working from home

WAI MYO KYAW waikyaw9999

🏠
Working from home
View GitHub Profile
@waikyaw9999
waikyaw9999 / wp-menu-item-name.php
Created February 1, 2024 04:35 — forked from gmaggio/wp-menu-item-name.php
[Wordpress] Get the Menu Name of the current page
<?php
/**
* Get the Menu Name of the current page
*
* $loc is the location name of the nav menu
*
* Source:
* http://wordpress.stackexchange.com/a/155833/1044
*
*/
@waikyaw9999
waikyaw9999 / gulp-cjs-to-esm.md
Created January 17, 2024 03:22 — forked from noraj/gulp-cjs-to-esm.md
Moving gulpfile from CommonJS (CJS) to ECMAScript Modules (ESM)

Moving gulpfile from CommonJS (CJS) to ECMAScript Modules (ESM)

Context

del v7.0.0 moved to pure ESM (no dual support), which forced me to move my gulpfile to ESM to be able to continue to use del.

The author sindresorhus maintains a lot of npm packages and does not want to provides an upgrade guide for each package so he provided a generic guide. But this guide is a bit vague because it's generic and not helping for gulp, hence this guide.

Guide

@waikyaw9999
waikyaw9999 / splitstringinhalf.js
Created September 4, 2021 08:02
Split string in half
const s = "At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat";
let middle = Math.floor(s.length / 2);
let before = s.lastIndexOf(' ', middle);
let after = s.indexOf(' ', middle + 1);
if (middle - before < after - middle) {
m
@waikyaw9999
waikyaw9999 / mongoengine_jsonencoder.py
Created December 26, 2020 10:25 — forked from corydolphin/mongoengine_jsonencoder.py
Fix: TypeError: ObjectId is not JSON serializable: A Flask JSONEncoder for Mongoengine documents. Specifically useful for use with Flask-Mongoengine.
from flask import Flask
from flask.json import JSONEncoder
from bson import json_util
from mongoengine.base import BaseDocument
from mongoengine.queryset.base import BaseQuerySet
class MongoEngineJSONEncoder(JSONEncoder):
def default(self,obj):
if isinstance(obj,BaseDocument):
return json_util._json_convert(obj.to_mongo())
class Deque:
def __init__(self):
self.items = []
def add_front(self, item):
self.items.insert(0, item)
def add_rear(self, item):
self.items.append(item)
@waikyaw9999
waikyaw9999 / bobp-python.md
Created November 21, 2020 13:31 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens