Skip to content

Instantly share code, notes, and snippets.

View hongbo-miao's full-sized avatar
❣️

Hongbo Miao hongbo-miao

❣️
View GitHub Profile
@tobitailor
tobitailor / get_barcode_from_image.js
Created June 1, 2010 19:33
Barcode recognition with JavaScript - Demo: http://bit.ly/djvUoy
/*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*/
(function(){
var UPC_SET = {
"3211": '0',
"2221": '1',
"2122": '2',
@unscriptable
unscriptable / tiny Promise.js
Created February 7, 2011 06:02
A minimalist implementation of a javascript promise
// (c) copyright unscriptable.com / John Hann
// License MIT
// For more robust promises, see https://github.com/briancavalier/when.js.
function Promise () {
this._thens = [];
}
Promise.prototype = {
@femto113
femto113 / transpose.js
Last active September 6, 2023 00:28
one line transpose for 2-dimensional Javascript arrays
function transpose(a)
{
return a[0].map(function (_, c) { return a.map(function (r) { return r[c]; }); });
// or in more modern dialect
// return a[0].map((_, c) => a.map(r => r[c]));
}
@solotimes
solotimes / example.js
Created April 29, 2012 06:55
javascript truncate filename
var s = 'this-is-a-very-very-very-long-file-name.jpg';
console.log(truncate(s, 100)); //this-is-a-very-very-very-long-file-name.jpg
console.log(truncate(s, 10)); //this-is-a-[...].jpg
console.log(truncate(s, 4)); //this[...].jpg
@tarunc
tarunc / kmeans.js
Created July 19, 2012 08:58
K-Means Clustering in Javascript
var distances = {
euclidean: function(v1, v2) {
var total = 0;
for (var i = 0; i < v1.length; i++) {
total += Math.pow(v2[i] - v1[i], 2);
}
return Math.sqrt(total);
},
manhattan: function(v1, v2) {
var total = 0;
@scttnlsn
scttnlsn / README.md
Created July 30, 2012 22:16
Pub/sub with MongoDB and Node.js

Pub/sub with MongoDB and Node.js

Setup:

$ mongo
> use pubsub
> db.createCollection('messages', { capped: true, size: 100000 })
> db.messages.insert({})
@hfcorriez
hfcorriez / test.js
Created August 19, 2012 09:21
Simple Pub/Sub model with NodeJs+Mongoose
var mongoose = require('mongoose');
var db = mongoose.createConnection('127.0.0.1', 'test');
// Make schema
var schema = mongoose.Schema({ name: String });
// Create subscribers collection
var subscribers = [];
// Hook `save` post method
@amaxwell01
amaxwell01 / interviewitems.MD
Created September 15, 2012 14:17
My answers to over 100 Google interview questions

##Google Interview Questions: Product Marketing Manager

  • Why do you want to join Google? -- Because I want to create tools for others to learn, for free. I didn't have a lot of money when growing up so I didn't get access to the same books, computers and resources that others had which caused money, I want to help ensure that others can learn on the same playing field regardless of their families wealth status or location.
  • What do you know about Google’s product and technology? -- A lot actually, I am a beta tester for numerous products, I use most of the Google tools such as: Search, Gmaill, Drive, Reader, Calendar, G+, YouTube, Web Master Tools, Keyword tools, Analytics etc.
  • If you are Product Manager for Google’s Adwords, how do you plan to market this?
  • What would you say during an AdWords or AdSense product seminar?
  • Who are Google’s competitors, and how does Google compete with them? -- Google competes on numerous fields: --- Search: Baidu, Bing, Duck Duck Go
@domenic
domenic / promises.md
Last active March 31, 2024 14:07
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@omurphy27
omurphy27 / transparent background image pattern overlay.css
Created March 26, 2013 04:59
CSS Transparent Background Image Pattern Overlay
/*Transparent pattern placed over an image, like we see on the bootstrap homepage: http://twitter.github.com/bootstrap/index.html*/
div {
width: 200px;
height: 200px;
display: block;
position: relative;
background: url(images/background-image.png);
}