Skip to content

Instantly share code, notes, and snippets.

😒
Nothing. Just me.

Taufik Nurrohman tovic

😒
Nothing. Just me.
Block or report user

Report or block tovic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tovic
tovic / codemirror-0.js
Last active Feb 15, 2018
CodeMirror Hotkeys for Bold and Italic
View codemirror-0.js
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(),
@tovic
tovic / module-pattern.js
Last active May 12, 2017
JavaScript Module Pattern
View module-pattern.js
/*! 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)
@tovic
tovic / gist:04c1b879f7423027615c4f45e2f716df
Created Sep 4, 2016 — forked from hiddentao/gist:5946053
Generate overridable getters and setters in Javascript
View gist:04c1b879f7423027615c4f45e2f716df
// 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?
@tovic
tovic / keyboard-event._key.js
Last active Sep 1, 2016
Just another polyfill for that `KeyboardEvent.key` property (lower-cased)
View keyboard-event._key.js
(function() {
// Key maps for the deprecated `KeyboardEvent.keyCode`
var keys = {
// control
8: 'backspace',
9: 'tab',
13: 'enter',
16: 'shift',
17: 'control',
@tovic
tovic / simplest-markdown-parser.php
Last active Aug 2, 2017
The Simplest PHP Markdown Parser
View simplest-markdown-parser.php
<?php
/*!
* =======================================================
* Author : Taufik Nurrohman
* URL : https://github.com/tovic
* License : MIT
* =======================================================
*
* -- CODE: ----------------------------------------------
@tovic
tovic / README.md
Created Jan 23, 2016 — forked from dciccale/README.md
Cross-browser triggerEvent function done with 127 bytes of JavaScript
View README.md

triggerEvent

Cross-browser function to trigger DOM events.

View gist:17865dfbbed8195b1ad1

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

View cb_addEventListener.js
/**
* 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
View miniuploader.html
<!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:
@tovic
tovic / universal-slug-url-generator.js
Created Feb 11, 2015
JavaScript Universal Slug URL Generator
View universal-slug-url-generator.js
/**
* Usage:
* ------
*
* <input type="text"> &rarr; <input type="text">
*
* <script>
* var input = document.getElementsByTagName('input');
* slug(input[0], input[1]);
* </script>
You can’t perform that action at this time.