Skip to content

Instantly share code, notes, and snippets.

View taufik-nurrohman's full-sized avatar
🍁
I ❤ U

Taufik Nurrohman taufik-nurrohman

🍁
I ❤ U
View GitHub Profile
@taufik-nurrohman
taufik-nurrohman / foobar.md
Created January 16, 2017 16:41 — forked from t32k/foobar.md
foo, bar, baz, qux, quux, corge, grault, garply, waldo, fred, plugh, xyzzy, thud
@taufik-nurrohman
taufik-nurrohman / codemirror-0.js
Last active February 15, 2018 16:53
CodeMirror Hotkeys for Bold and Italic
editor.addKeyMap({
// bold
'Ctrl-B': function(cm) {
var s = cm.getSelection(),
t = s.slice(0, 2) === '**' && s.slice(-2) === '**';
cm.replaceSelection(t ? s.slice(2, -2) : '**' + s + '**', 'around');
},
// italic
'Ctrl-I': function(cm) {
var s = cm.getSelection(),
@taufik-nurrohman
taufik-nurrohman / module-pattern.js
Last active May 12, 2017 17:09
JavaScript Module Pattern
/*! JavaScript Module Pattern by Taufik Nurrohman <https://github.com/tovic> */
(function(win, doc, NS) {
(function($) {
// module version
$.version = '1.0.0';
// collect all instance(s)
@taufik-nurrohman
taufik-nurrohman / gist:04c1b879f7423027615c4f45e2f716df
Created September 4, 2016 08:53 — forked from hiddentao/gist:5946053
Generate overridable getters and setters in Javascript
// see blog post: http://www.hiddentao.com/archives/2013/07/08/generate-overridable-getters-and-setters-in-javascript/
Function.prototype.generateProperty = function(name, options) {
// internal member variable name
var privateName = '__' + name;
options = options || {};
options.get = ('undefined' === typeof options.get ? true : options.get );
options.set = ('undefined' === typeof options.set ? true : options.set );
// pre-initialise the internal variable?
@taufik-nurrohman
taufik-nurrohman / keyboard-event._key.js
Last active September 1, 2016 04:22
Just another polyfill for that `KeyboardEvent.key` property (lower-cased)
(function() {
// Key maps for the deprecated `KeyboardEvent.keyCode`
var keys = {
// control
8: 'backspace',
9: 'tab',
13: 'enter',
16: 'shift',
17: 'control',
@taufik-nurrohman
taufik-nurrohman / simplest-markdown-parser.php
Last active December 15, 2022 12:37
The Simplest PHP Markdown Parser
<?php
/*!
* =======================================================
* Author : Taufik Nurrohman
* URL : https://github.com/taufik-nurrohman
* License : MIT
* =======================================================
*
* -- CODE: ----------------------------------------------
@taufik-nurrohman
taufik-nurrohman / README.md
Created January 23, 2016 15:16 — forked from dciccale/README.md
Cross-browser triggerEvent function done with 127 bytes of JavaScript

triggerEvent

Cross-browser function to trigger DOM events.

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

/**
* Cross Browser helper to addEventListener.
*
* @param {HTMLElement} obj The Element to attach event to.
* @param {string} evt The event that will trigger the binded function.
* @param {function(event)} fnc The function to bind to the element.
* @return {boolean} true if it was successfuly binded.
*/
var cb_addEventListener = function(obj, evt, fnc) {
// W3C model
<!DOCTYPE html>
<!-- This is the shortest Image Uploader ever :)
And you can even make it shorter if you don't
want all the drag'n drop thing. -->
<!--
AUTHOR: @paulrouget <paul@mozilla.com>
LICENSE: