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
@mubaidr
mubaidr / asset-loader.js
Created August 20, 2018 15:45
load image & sound assets using promises
/**
* Loads the provided list of assets and return the ready to use list
* @param {Array<Object>} arr Assets array to load
* @returns {Array<Object>} Collection of loaded results
*/
static loadAssets(assets) {
const promises = []
assets.forEach(a => {
@mubaidr
mubaidr / sequelize-schema-file-generator.js
Last active December 27, 2018 04:46 — forked from manuelbieh/sequelize-schema-file-generator.js
Automatically generates migration files from your sequelize models
const fs = require('fs')
const { sequelize } = require('./api/db/models')
const { models } = sequelize
function toSnakeCase(str, upper) {
if (str.split().every(s => s.toLowerCase() === s)) return str
const snake = str.replace(/([A-Z])/g, $1 => `_${$1.toLowerCase()}`)
/**
* Generates models from the given DB in to models directory
*/
require('dotenv').config()
const Sequelize = require('sequelize')
const SequelizeAuto = require('sequelize-auto')
const fs = require('fs')
const path = require('path')
const fs = require('fs');
const Replace = require('replace');
const basePath = './api/';
const modelsPath = './api/db/models/';
const models = fs.readdirSync(modelsPath);
models.forEach(model => {
const splitted = model
.replace('.js', '')
Sub Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ThisWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & xWs.Name & ".xlsx"
Application.ActiveWorkbook.Close False

Setup npm for native addons build (nodejs, electronjs, nw.js etc):

  • Install Vs 2015 or vs 2017 build tools
    • from VS setup // OR
    • npm install --global --production windows-build-tools
  • npm config set msvs_version 2017 // Or2015
  • set VCTargetsPath environment variable to:
    • for 2017: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets
  • for 2015: C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140
@mubaidr
mubaidr / migrate-assert-to-expect.js
Created August 14, 2019 13:46 — forked from robertleeplummerjr/migrate-assert-to-expect.js
A script that migrates from using assert to jest's expect
const { parse } = require('acorn');
const fs = require('fs');
const file = fs.readFileSync('./__tests__/file-name.js').toString();
const rootAST = parse(file, {
locations: true
});
function traverse(ast) {
if (Array.isArray(ast)) {
for (let i = 0; i < ast.length; i++) {
@mubaidr
mubaidr / gh-pages-deploy.md
Created August 16, 2019 17:49 — forked from cobyism/gh-pages-deploy.md
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

const path = require('path')
const fs = require('fs')
const fg = require('fast-glob')
async function start() {
const glob = path
.join(__dirname, '..', '__tests__', '**/*.ts')
.replace(/\\/g, '/')
const filesPaths = fg.sync(glob, {
/**
* Balanced histogram thresholding
* @param {number[]} histogram Histogram
* @return {number} Threshold value
*/
function getThreshold(histogram) {
let iS = 0
let iE = 255
let iM = 127
let wL = histogram.reduce((sum, val, index) => {