Skip to content

Instantly share code, notes, and snippets.

View Munawwar's full-sized avatar
🍪
Cookies

Munawwar Munawwar

🍪
Cookies
View GitHub Profile
@Munawwar
Munawwar / ExcelReading.java
Last active November 2, 2022 08:37
Java - Apache POI - Convert XLS/XLSX to CSV
/*
* Dependencies: Apache POI Library from http://poi.apache.org/
*/
package poi_excels;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
@Munawwar
Munawwar / ExcelOleDb.cs
Last active September 9, 2016 11:28
C# .NET - Convert Excel 2007 (XLSX) to CSV using OLE DB
/*
* Dependency: Office 2007
* OR
* Install 2007 Office System Driver - Data Connectivity Components from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en
* No references or anything needed to be added.
*
* Other Notes:
* 1. There is a 64-bit version too. But I am using the 32-bit one.
* 2. For Office 2010. there is a 'Microsoft Access Database Engine 2010 Redistributable' at http://www.microsoft.com/downloads/en/details.aspx?FamilyID=C06B8369-60DD-4B64-A44B-84B371EDE16D
* 3. I am Using OLEDB here. ODBC can also be used.
@Munawwar
Munawwar / ExcelDataReader.cs
Last active January 14, 2020 12:19
C# - Excel Data Reader Library - Convert Excel (XLSX or XLS) to CSV
/*
* Dependency : Excel Data Reader from http://exceldatareader.codeplex.com/
* You must add the references to the Dlls (downloaded from the link above) with Visual Studio.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel;
@Munawwar
Munawwar / test.html
Last active January 10, 2017 01:45
IE8 polyfill for HTML5 Range object's startContainer, startOffset, endContainer and endOffset properties.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
/*
This code is a IE8 (and below), polyfill for HTML5 Range object's startContainer,
startOffset, endContainer and endOffset properties.
*/
(function () {
function findTextNode(node, text) {
@Munawwar
Munawwar / selection.js
Created September 26, 2012 10:02 — forked from visnup/selection.js
IE8 equivalent of HTML5/W3C Range object's startContainer,startOffset,endContainer and endOffset properties
(function selectionPolyfill(window, document) {
if (window.getSelection || !document.selection) return;
// convert an IE TextRange to a W3C one
function convert(range, startOrEnd) {
var point = range.duplicate()
, result = {};
// point is either the start or end of the range
point.collapse(startOrEnd);
@Munawwar
Munawwar / flexbox.html
Last active September 9, 2021 07:02
HBox and VBox layout with CSS3 flexbox
<!DOCTYPE HTML>
<html>
<head>
<!-- HBox and VBox layouts have been implementated with many libraries/toolkits on
different platforms and languages (like ExtJS,QT,GTK,.NET...).
This tries to achieve the same but with CSS only.
Supported browsers: IE 10+, Safari 6.1, Latest FF, Chrome -->
<style type="text/css">
html, body {
@Munawwar
Munawwar / contrast.js
Last active December 31, 2015 17:09
Two functions: i. To find contrast (actually luma) ratio of two colors. ii. To find contrast grey shade of any color.
/* Taken from http://stackoverflow.com/a/13558570.
* aka inverse gamma. Some call it "inverse sRGB companding".
* All the constants are taken from sRGB spec.
* Read about it at http://en.wikipedia.org/wiki/SRGB (I didn't understand how they derived the approximation).
*/
function linear(R) { //in sRGB as hex string
var s = parseInt(R, 16) / 255;
if (s <= 0.04045) {
return s / 12.92;
} else {
@Munawwar
Munawwar / html-validator.js
Last active April 18, 2022 07:38
Unbalanced HTML markup detection
/**
* Detect unsafe (and potentially unsafe) unbalanced tags in a given HTML snippet.
* Hints taken from an html parse (https://gist.github.com/cburgmer/2877758).
*
* Example:
* An unclosed div tag is considered unsafe, because if the snippet is pasted in between two div tags
* then it could end up breaking the HTML document.
* Self closing tags (tags that you can intentioanlly leave open like <table><tr><td>some text</table>) are also considered unsafe, for the same reason.
* However an unclosed void tag (like meta tag) is safe, because browsers will ignore it without any side effects.
*
/**
* jQuery 2.1.3's parseHTML (without scripts options).
* Unlike jQuery, this returns a DocumentFragment, which is more convenient to insert into DOM.
* MIT license.
*
* If you only support Edge 13+ then try this:
function parseHTML(html, context) {
var t = (context || document).createElement('template');
t.innerHTML = html;
return t.content;
<!DOCTYPE html>
<html>
<head>
</head>
<script>
/**
* The problem: Binding functions (using function.bind()) and adding listeners is messy,
* since a bind creates a new function everytime and one needs to keep reference to the new function.
* When having many event handlers this gets messy.
*