Skip to content

Instantly share code, notes, and snippets.

View mubaidr's full-sized avatar
🎯
Adding bugs to web applications!

Muhammad Ubaid Raza mubaidr

🎯
Adding bugs to web applications!
View GitHub Profile
git for-each-ref --format='%(refname:lstrip=3)' --sort=-creatordate --count 1
@mubaidr
mubaidr / publish-ghpages.md
Created March 26, 2020 06:21 — forked from tduarte/publish-ghpages.md
If you need to force push an subtree
git checkout master # you can avoid this line if you are in master...
git subtree split --prefix dist -b gh-pages # create a local gh-pages branch containing the splitted output folder
git push -f origin gh-pages:gh-pages # force the push of the gh-pages branch to the remote gh-pages branch at origin
git branch -D gh-pages # delete the local gh-pages because you will need it: ref
@mubaidr
mubaidr / publish-subtree.sh
Created March 26, 2020 06:43
force push commit subtree to remote
# create new subtree from latest commit for dist/
commit=$(git subtree split --prefix=dist/ -b gh-pages)
# force push this commit to remote
git push mubaidr.github.io $commit:master --force
# git subtree push --prefix=dist/ mubaidr.github.io master
@mubaidr
mubaidr / add_timestamp_triggers.sql
Created April 4, 2020 07:04
Add timestamps columns (created_at, updated_at) and triggers (update updated_at on row update) to all user tables in postgreSQL
-- add timestamps (created_at, updated_at)
-- add trigger for timestamp updated_at
CREATE OR REPLACE FUNCTION add_custom_timestamps() RETURNS void AS $$
DECLARE
row_data RECORD;
-- row_data information_schema.tables%ROWTYPE;
BEGIN
FOR row_data IN
@mubaidr
mubaidr / nodejs-cheatsheet.js
Created July 17, 2020 06:09 — forked from LeCoupa/nodejs-cheatsheet.js
Complete Node.js CheatSheet --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
/* *******************************************************************************************
* THE UPDATED VERSION IS AVAILABLE AT
* https://github.com/LeCoupa/awesome-cheatsheets
* ******************************************************************************************* */
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html
function getSvgAsImage(svgElem, viewBox) {
// TODO: add x,y to w,h
var canvas = document.createElement('canvas')
canvas.width = viewBox[2]
canvas.height = viewBox[3]
var ctx = canvas.getContext('2d')
ctx.fillStyle = '#fff'
ctx.fillRect(0, 0, canvas.width, canvas.height)
var options = {
// This file was initially generated by Windows Terminal Preview 1.1.1671.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@mubaidr
mubaidr / trim_canvas.js
Created October 3, 2020 16:28 — forked from timdown/trim_canvas.js
Returns a copy of a canvas element with surrounding transparent space removed
var trimCanvas = (function() {
function rowBlank(imageData, width, y) {
for (var x = 0; x < width; ++x) {
if (imageData.data[y * width * 4 + x * 4 + 3] !== 0) return false;
}
return true;
}
function columnBlank(imageData, width, x, top, bottom) {
for (var y = top; y < bottom; ++y) {
@mubaidr
mubaidr / rdp.ts
Created December 28, 2020 17:05
Ramer–Douglas–Peucker algorithm in typescript
import { Polygon } from './types/ShapeType'
import { perpendicularDistance } from './utilities'
// distance between two points
function distance(p1: Point, p2: Point): number {
return Math.sqrt((p2.x - p1.x) ** 2 + (p2.y - p1.y) ** 2)
}
// perpendicular distance of a point from a line
CREATE FUNCTION get_Exact_Date_diff(@date SMALLDATETIME,@date2 SMALLDATETIME)
returns VARCHAR(50)
AS
BEGIN
DECLARE @date3 SMALLDATETIME
DECLARE @month INT,@year INT,@day INT