Skip to content

Instantly share code, notes, and snippets.

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

Muhammad Ubaid Raza mubaidr

:shipit:
Adding bugs to web applications!
View GitHub Profile
<div id="consolelog" style="font-family: 'Courier New', Courier, monospace; font-size: 12px; margin: 40px 30px 0px; background-color: white; border: 2px solid black; padding: 10px;"></div>
<input type="text" id="consoleinput" style="margin: 0px 30px; width: 400px;" onkeypress="return evalConsoleInput(event, this.value);" />
<script type="text/javascript">
var appendConsole = function(message, type) {
var color = "black";
if (type === "error") {
color = "red";
} else if (type === "debug") {
@mubaidr
mubaidr / selector
Created September 14, 2014 06:09
A small snippet to select element sin JavaScript using CSS selector syntax.
function $$(xpath,root) {
2 xpath = xpath
3 .replace(/((^|\|)\s*)([^/|\s]+)/g,'$2.//$3')
4 .replace(/\.([\w-]+)(?!([^\]]*]))/g, '[@class="$1" or @class$=" $1" or @class^="$1 " or @class~=" $1 "]')
5 .replace(/#([\w-]+)/g, '[@id="$1"]')
6 .replace(/\/\[/g,'/*[');
7 str = '(@\\w+|"[^"]*"|\'[^\']*\')';
8 xpath = xpath
9 .replace(new RegExp(str+'\\s*~=\\s*'+str,'g'), 'contains($1,$2)')
10 .replace(new RegExp(str+'\\s*\\^=\\s*'+str,'g'), 'starts-with($1,$2)')
@mubaidr
mubaidr / README.md
Last active August 29, 2015 14:07 — forked from addyosmani/README.md

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@mubaidr
mubaidr / memorySizeOfObject.js
Created April 4, 2016 10:52
calculate memory size of javascript object, it is not a accurate value!
function memorySizeOf(obj) {
var bytes = 0;
function sizeOf(obj) {
if(obj !== null && obj !== undefined) {
switch(typeof obj) {
case 'number':
bytes += 8;
break;
case 'string':
@mubaidr
mubaidr / Startup.cs
Created December 26, 2016 15:09 — forked from tanveery/Startup.cs
LinkedIn APIs for .NET
public void ConfigureAuth(IAppBuilder app)
{
// ...
var linkedInOptions = new LinkedInAuthenticationOptions();
linkedInOptions.ClientId = "Your LinkedIn API Key";
linkedInOptions.ClientSecret = "Your LinkedIn Secret Key";
linkedInOptions.Scope.Add("r_fullprofile");
@mubaidr
mubaidr / .eslintrc.json
Created July 7, 2017 03:42
Eslint config
{
"root": true,
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 6,
@mubaidr
mubaidr / bootstrap-nav-bar.js
Created September 30, 2017 16:20
Enable bootstrap collapsible navbar without jQuery
const classChildren = x => document.getElementsByClassName(`navbar-${x}`)[0];
classChildren(‘toggle’).addEventListener(‘click’, () => {
classChildren(‘collapse’).classList.toggle(‘collapse’);
}, false);
@mubaidr
mubaidr / get_barcode_from_image.js
Created May 6, 2018 16:57 — forked from tobitailor/get_barcode_from_image.js
Barcode recognition with JavaScript - Demo: http://bit.ly/djvUoy
/*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*/
(function(){
var UPC_SET = {
"3211": '0',
"2221": '1',
"2122": '2',
@mubaidr
mubaidr / index.html
Created July 25, 2018 16:50 — forked from mac2000/index.html
brain.js demo
<!DOCTYPE html>
<html>
<head>
<title>brain.js</title>
<script src="https://cdn.rawgit.com/BrainJS/brain.js/develop/browser.js"></script>
<script>
function DrawableCanvas(el) {
const px = 10
const ctx = el.getContext('2d')
let x = []
@mubaidr
mubaidr / JavaScript-toProperCase.js
Created August 13, 2018 17:50
JavaScript-toProperCase
String.prototype.toProperCase = function (convertCamelCase) {
var words = this.split(' ');
var proper = [];
for (var index in words) {
if (convertCamelCase) {
proper.push(words[index].replace(/([A-Z])/g, ' $1')
.replace(/^./, function (str) {
return str.toUpperCase();
}));