Skip to content

Instantly share code, notes, and snippets.

View retrohacker's full-sized avatar

William Blankenship retrohacker

View GitHub Profile
var numberOfUsers = 500
function harvest() {
$("#search").scrollTop($("#search")[0].scrollHeight);
var bs = $('*[data-capture="noiseClicked"]')
var len = bs.length
console.log(len)
if ( len > numberOfUsers) {
follow()
} else {
setTimeout(harvest, Math.floor(Math.random() * 500) + 1);
@retrohacker
retrohacker / wrapper.js
Created September 9, 2014 15:29
NodeWebkit wrapper
#!/usr/bin/node
/**
* Import dependencies
*/
var exec = require('child_process').exec
var nw = require('nodewebkit').findpath
var path = require('path')
/**
function oops(y) {
return [arguments, function () {return y}]
};
vals=oops(2);
y1=vals[1]();
vals[0][0]=3; // change "y"
y2=vals[1]();
// varies depending on strict mode or not
[y1,y2]
FROM ubuntu:trusty
# Setup sane dev environment
RUN apt-get update
RUN apt-get upgrade -y --force-yes
RUN apt-get install openssh-server -y --force-yes
RUN apt-get install sudo -y --force-yes
# Setup user ns w/ ssh keys
RUN mkdir /home/user
{
"/etc/annvix-release" : ["Annvix"],
"/etc/arch-release" : ["Arch Linux"],
"/etc/arklinux-release" : ["Arklinux"],
"/etc/aurox-release" : ["Aurox Linux"],
"/etc/blackcat-release" : ["BlackCat"],
"/etc/cobalt-release" : ["Cobalt"],
"/etc/lsb-release" : ["Chakra","IYCC","Linux Mint","Ubuntu Linux"],
"/etc/conectiva-release" : ["Conectiva"],
"/etc/debian_version" : ["Debian"],
/*
same file name, two different files.
*/
var fs = require('fs')
var file = './test.js'
var test = require(file)()

Error Handling

There are two different ways to handle errors in JavaScript. You can treat them as variables, or throw them. Both have their use cases, and you can convert back and forth between them using design patterns. Lets take a look at how each behave.

Try-Catch

If you are coming from another language, you are probably already familiar with try catch. Here is a basic example:

function trycatch() {
#! /bin/sh
### BEGIN INIT INFO
# Provides: nodejs
# Required-Start: $remote_fs $syslog $network $portmap $time $localfs $named
# Required-Stop: $remote_fs $syslog $network $portmap $time $localfs $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: A simple webserver demonstrating a node.js init script
# Description: This shows the best way to construct a node.js init script
# It implements the best practices described in
#! /bin/sh
### BEGIN INIT INFO
# Provides: helloInit
# Required-Start: $remote_fs $syslog $network $portmap $time $localfs $named
# Required-Stop: $remote_fs $syslog $network $portmap $time $localfs $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: A simple webserver demonstrating a node.js init script
# Description: This shows the best way to construct a node.js init script
# It implements the best practices described in
var tar = require('tar')
var fstream = require('fstream')
function buildTar() {
var converter = tar.Pack()
var tarball = fstream.
Writer({path:"./docker.tar",mode:755})
converter.pipe(tarball)
fstream
.Reader("./")