Skip to content

Instantly share code, notes, and snippets.

@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active July 21, 2024 01:20
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@davidcalhoun
davidcalhoun / js-best-practices.md
Created September 7, 2011 18:33
JavaScript best practices

JavaScript Best Practices

Code conventions

Closing/opening brackets

Although this isn't a problem in other languages, because of semicolon insertion, there could be problems if you don't place the bracket on the opening line:

// no:
function()
{
@bsodmike
bsodmike / plupload_FilesAdded.js
Created November 16, 2011 12:50
Remove files from the plupload file 'Queue'
uploader.bind('FilesAdded', function(up, files) {
//console.log (up);
//console.log (files);
$.each(files, function(i, file) {
$('#filelist').append(
'<div id="' + file.id + '">' +
file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' +
'<a href="" class="remove btn error">X</a></div>'
);
$('#uploadfiles').css('display', 'initial');
@liamcurry
liamcurry / gist:2597326
Created May 4, 2012 19:56
Vanilla JS vs jQuery

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@JedWatson
JedWatson / 1-proposal.md
Last active January 2, 2024 17:59
Proposal: adding reverse-relationship population to Mongoose (as implemented in KeystoneJS)

I've developed a useful feature in KeystoneJS that lets you populate a relationship from either side, while only storing the data on one side, and am looking for feedback on whether it is something that could / should be brought back into mongoose itself. (It might be possible to add as a separate package but I suspect there'd be too much rewriting of mongoose internals for that to be a good idea).

I've added this as an issue in mongoose for consideration: #1888 but am leaving this gist in place because the examples are easier to read.

I've used Posts and Categories as a basic, contrived example to demonstrate what I'm talking about here; in reality you'd rarely load all the posts for a category but there are other real world cases where it's less unreasonable you'd want to do this, and Posts + Categories is an easy way to demo it.

The problem

The built-in population feature is really useful; not just for

@ademilter
ademilter / gist:8972161
Created February 13, 2014 09:20
share & share count
// SHARE COUNT
$.getJSON("https://graph.facebook.com/fql?q=SELECT like_count FROM link_stat WHERE url=" + encodeURIComponent('"' + Screenshot.Meta.full_url + '"') + " &callback=?", function(t) {
t.data[0] && $("#share-button-fb .shot-social-count").html(shorterTotal(t.data[0].like_count))
})
$.getJSON("http://cdn.api.twitter.com/1/urls/count.json?url=" + encodeURIComponent(Screenshot.Meta.full_url) + "&callback=?", function(t) {
t.count && $("#share-button-twitter .shot-social-count").html(shorterTotal(t.count))
})
@iksose
iksose / restAPI.markdown
Last active September 21, 2023 06:39
Creating a REST API using Node.js, Express, and MongoDB

###Creating a REST API using Node.js, Express, and MongoDB

####Installing Node.js

Go to http://nodejs.org, and click the Install button. Run the installer that you just downloaded. When the installer completes, a message indicates that Node was installed at /usr/local/bin/node and npm was installed at /usr/local/bin/npm. At this point node.js is ready to use. Let’s implement the webserver application from the nodejs.org home page. We will use it as a starting point for our project: a RESTful API to access data (retrieve, create, update, delete) in a wine cellar database.

Create a folder named nodecellar anywhere on your file system. In the wincellar folder, create a file named server.js.

@ustun
ustun / gist:5ee3250acf938e4115c6
Last active March 20, 2019 14:20
Ustun Ozgur Yazilim Is Ilani

Not: Mart 2016 itibariyle aşağıdaki ilan geçersizdir. Şu an için açık pozisyon bulunmamaktadır.

@girlcheese
girlcheese / gist:29acea17ba606b01153c
Last active June 12, 2020 03:31
slotRenderEnded listener event (DFP)
googletag.pubads().addEventListener("slotRenderEnded", function(event) {
//console.log("googletag slotRenderEnded", event.slot.b.f);
var containerId = "";
// WARN: Fragile access of private object within DFP Slot Object returned with the event
// It's the only way to get access to the id of the DOM element attached to the slot
// FIXME: Ideally we need to contact Google and request a public API method to return the id
if (typeof event.slot !== "undefined") {
if (typeof event.slot.b !== "undefined") {
@ademilter
ademilter / font-face-builder.scss
Last active September 19, 2020 19:23
font-face builder
$font-family: (
group: serif,
id: regular,
name: 'Equity Regular',
fallback: (georgia, serif),
weight: normal,
style: normal,
file-name: 'equity_text_b_regular-webfont'
), (
group: serif,