Skip to content

Instantly share code, notes, and snippets.

@madhums
madhums / expressjs-base64-image.js
Created March 9, 2012 09:02 — forked from hackable/expressjs-base64-image.js
Node.js base64 encode a downloaded image for use in data URI
express = require("express")
request = require("request")
BufferList = require("bufferlist").BufferList
app = express.createServer(express.logger(), express.bodyParser())
app.get "/", (req, res) ->
if req.param("url")
url = unescape(req.param("url"))
request
uri: url
encoding: 'binary'
@madhums
madhums / Preferences.sublime-settings
Created April 16, 2012 23:36
my sublime text settings!
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"draw_minimap_border": true,
"find_selected_text": true,
"font_face": "Bitstream Vera Sans Mono",
"font_options":
[
"subpixel_antialias",
"bold"
],
@madhums
madhums / style_guide.md
Created April 21, 2012 11:42 — forked from dominictarr/style_guide.md
style guide

High level style in javascript.

Opinions are like assholes, every one has got one.

This one is mine.

Punctuation: who cares?

Punctuation is a bikeshed. Put your semicolons, whitespace, and commas where you like them.

@madhums
madhums / bended-shadow.css
Created May 27, 2012 11:18 — forked from nrrrdcore/bending-shadow.css
Simple Bended-Shadow CSS: Create the Bended Photo Effect without writing a million divs.
.bended-shadow {
position: relative;
width: 500px;
margin: 200px auto;
}
.bended-shadow::before, .bended-shadow::after {
content: '';
position: absolute;
width: 60%;
@madhums
madhums / apple-shadow.css
Created May 27, 2012 11:18 — forked from nrrrdcore/apple-shadow.css
Bending Shadows Backwards: Apple.com's Container CSS Sorcery
.shadow-stuff {
-moz-border-radius: 0% 0% 100% 100% / 0% 0% 8px 8px;
-webkit-border-radius: 0% 0% 100% 100% / 0% 0% 8px 8px;
border-radius: 0% 0% 100% 100% / 0% 0% 8px 8px;
-moz-box-shadow: rgba(0,0,0,.30) 0 2px 3px;
-webkit-box-shadow: rgba(0,0,0,.30) 0 2px 3px;
box-shadow: rgba(0,0,0,.30) 0 2px 3px;
}
.container {
@madhums
madhums / express-pagination.js
Created July 23, 2012 00:23 — forked from xjamundx/express-pagination.js
sample pagination using express route-specific middleware
// articles per page
var limit = 10;
// pagination middleware function sets some
// local view variables that any view can use
function pagination(req, res, next) {
var page = parseInt(req.params.page) || 1,
num = page * limit;
db.articles.count(function(err, total) {
res.local("total", total);
@madhums
madhums / gist:3311709
Created August 10, 2012 06:21
TextMate 2 .tm_properties

This is all based on the [alpha release][1].

Properties

From the built-in help system:

For many settings TextMate will look for a .tm_properties file in the current folder and in any parent folders (up to the user’s home folder).

These are simple setting = value listings where the value is a format string in which other variables can be referenced.

@madhums
madhums / createPagination.js
Created August 20, 2012 04:54
create pagination helper
res.locals.createPagination = function (pages, page) {
var url = require('url')
, qs = require('querystring')
, params = qs.parse(url.parse(req.url).query)
, str = ''
params.page = 0
var clas = page == 0 ? "active" : "no"
str += '<li class="'+clas+'"><a href="?'+qs.stringify(params)+'">First</a></li>'
for (var p = 1; p < pages; p++) {
@madhums
madhums / _intersection.js
Created August 21, 2012 18:04
intersection of array of objects
_.intersectionObjects = _.intersect = function(array) {
var slice = Array.prototype.slice; // added this line as a utility
var rest = slice.call(arguments, 1);
return _.filter(_.uniq(array), function(item) {
return _.every(rest, function(other) {
//return _.indexOf(other, item) >= 0;
return _.any(other, function(element) { return _.isEqual(element, item); });
});
});
@madhums
madhums / producer.js
Created August 30, 2012 13:17
zmq - passing objects to workers
var zmq = require('zmq')
, sock = zmq.socket('push');
sock.bindSync('tcp://127.0.0.1:3000');
console.log('Producer bound to port 3000');
setTimeout(function(){
console.log('sending work');
var data = {