Skip to content

Instantly share code, notes, and snippets.

View shovon's full-sized avatar
💻
Working on my own projects

Sal Rahman shovon

💻
Working on my own projects
View GitHub Profile
@shovon
shovon / reddit-r-reactjs.css
Last active August 29, 2015 14:15
The CSS code for reddit/r/reactjs
.flair-somename {
background: #000;
border: 1px solid #000;
color: #fff;
}
/* Theme: DSCVRY by doingstuffcarl/jillpatel (/r/dscvry)
Night Mode: nm.reddit.com/r/YOUR_SUBREDDIT */
@shovon
shovon / monads.js
Created February 23, 2015 01:00
I think I'm starting to understand monads...
function bind(m, g) {
if (m === null) { return null; }
return g(m);
}
function getBothGrandFathers(p) {
return bind(father(p), function (dad) {
return bind(father(dad), function (gf1) {
return bind(mother(p), function (mom) {
return bind(father(mom), function (gf2) {
@shovon
shovon / async.js
Last active August 29, 2015 14:16
Me practicing monads more.
function Monad(a) {
this._value = a;
}
/**
* callback: (err: Error, isEqual: boolean)
*/
Monad.prototype.value = function (callback) {
setImmediate(callback.bind(null, null, this._value));
};

Display a list of the most commonly used commands

$ history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -nr | head

Credit goes to: http://stackoverflow.com/a/68390/538570

@shovon
shovon / gist:ffa75ee28b1fac02243d
Last active August 29, 2015 14:16
Possibly asynchronous data flow in a monadic style?
var assert = require('assert');
function Monad(a) {
this._value = a;
}
Monad.unit = function (a) {
return new Monad(a);
};
@shovon
shovon / gist:5685073d03829f3b63d0
Last active March 25, 2018 16:10
Haskell-style monads in JavaScript (ES6).
'use strict';
class Monad {
constructor(a) { this._value = a; }
'>>='(f) { return f(this.value()); }
static create(a) { return new Monad(a); }
value() { return this._value; }
}
var val = Monad.create(10) ['>>=']
@shovon
shovon / README.md
Last active August 29, 2015 14:17
Share images on Imgur, on the browser

Example usage

share(imgDOM, clientID)
  .then(function (data) {
    // Take a look at the example response...
  });

Dependency

@shovon
shovon / increase_swap.sh
Created April 10, 2015 15:18
Increasing swap size. Only tested on the ubuntu/trusty64 Vagrant box. CREDIT GOES TO ---> http://jeqo.github.io/blog/devops/vagrant-quickstart/
#!/bin/sh
# size of swapfile in megabytes
swapsize=8000
# does the swap file already exist?
grep -q "swapfile" /etc/fstab
# if not then create it
if [ $? -ne 0 ]; then
@shovon
shovon / LayoutItemView.js
Last active August 29, 2015 14:22
Introduces the "regions" feature into Backbone.Marionette.ItemView, albeit with a different API.
var LayoutItemView = Backbone.Marionette.ItemView.extend({
render: function () {
var retval =
Backbone.Marionette.ItemView.prototype.render.call(this, arguments);
var self = this;
if (typeof this.regions === 'object') {
_.each(_.keys(this.regions), function (key) {
var view = self.regions[key](self.model);
view.render();
@shovon
shovon / quicksort.js
Last active August 29, 2015 14:23
Quicksort in 5 lines of JavaScript
function quicksort ([x, ...xs]) {
if (x === undefined) { return xs; }
return [ ...quicksort([for (a of xs) if (a <= x) a]), x,
...quicksort([for (a of xs) if (a > x) a]) ];
}