Skip to content

Instantly share code, notes, and snippets.

View DTrejo's full-sized avatar

David Trejo DTrejo

View GitHub Profile
@mixin table-base
th
text-align: center
font-weight: bold
td, th
padding: 2px
@mixin left($dist)
float: left
margin-left: $dist
var response = require('ringo/webapp/response');
var model = require('./model');
exports.index = function index(req) {
//last 10 posts
var posts = model.Post.query().select();//.slice(0,10);
return response.skinResponse('skins/index.html', {
posts: posts,
});
there should be js here but there isn't so this should throw an error.
function getDescription(barcode) {
var exec = require('child_process').exec,
child,
description;
// async command line call, takes its time to finish
child = exec('curl http://www.upcdatabase.com/item/' + barcode + ' -s | grep Description',
function (error, stdout, stderr) {
if(stderr.length > 0){
sys.puts('exec stderr: ' + stderr);
// Used to run code in a directory and rerun it if any files are changed.
// usage: node run.js servercode.js
// servercode.js is whatever js file you want to run with node.
// Excludes filetypes in the ignoreExtensions array
var sys = require('sys'),
fs = require('fs'),
spawn = require('child_process').spawn,
child, // child process which runs the actual code
ignoreExtensions = ['.dirtydb', '.db'];
var item = { "hdbarcode": hdbarcode, "description": description };
// 2nd argument is callback
getDescription(item.hdbarcode, function(upcDescrip){
db.save(null, item, function (err, meta) {
// This does not change item on line 1. Why?
item.key = meta.key;
sys.puts('saved ' + JSON.stringify(item) + ' as '+ meta.key);
});
});
// Used to run code in a directory and rerun it if any files are changed.
// usage: node run.js servercode.js
// servercode.js is whatever js file you want to run with node.
// Excludes filetypes in the ignoreExtensions array
var sys = require('sys'),
fs = require('fs'),
spawn = require('child_process').spawn,
child, // child process which runs the actual code
ignoreExtensions = ['.dirtydb', '.db']; // Change this to your liking
var static = require('node-static');
//
// Create a node-static server instance to serve the './public' folder
//
var file = new(static.Server)('./public');
require('http').createServer(function (request, response) {
request.addListener('end', function () {
//
var sys = require('sys')
, url = require('url')
, http = require('http')
, eyes = require('eyes')
, querystring = require('querystring')
, io = require(__dirname + '/lib/socket.io-node')
, PORT = 80 // MAKE SURE THIS IS SAME AS SOCKET.IO
, static = require('node-static')
public class Bitops {
// Takes a character and returns the number of ones
// contained in its binary representation
static int numOnes(char c) {
int hex = (int) c;
int sum = 0;
// we want unsigned comparison
// this works fine if java uses 2s complement (it does I think).
while (hex > 0) {