Skip to content

Instantly share code, notes, and snippets.

View riston's full-sized avatar

Risto Novik riston

View GitHub Profile
@riston
riston / gist:2463820
Created April 22, 2012 11:57
Async code flow forEach
var names = ['Juhan', 'Mikk', 'Tuuli', 'Oskar'];
var newList = [];
function welcome(name, callback) {
name += ', hello';
console.log(name);
newList.push(name);
callback(null, name);
}
@riston
riston / gist:2973580
Created June 22, 2012 15:43
Reading /dev/psaux stream with nodejs
var fs = require('fs');
var readStream = fs.ReadStream('/dev/psaux');
var mouseMovements = [];
readStream.on('data', function(packet) {
var buf = packet.readInt8(0);
var mouse = {
leftBtn: !!(buf & 1)
@riston
riston / gist:3016944
Created June 29, 2012 09:40
Random number generating (Box-Muller)
var Random = {
/**
* Numbers between ~( -2 to 2 )
* http://stackoverflow.com/questions/75677/converting-a-uniform-distribution-to-a-normal-distribution
* http://c-faq.com/lib/gaussian.html
*/
gaussian: function() {
var x1, x2, r;
@riston
riston / bot-download.sh
Created July 4, 2012 15:46
RSBot downloading script
#!/bin/sh
download_page='http://links.powerbot.org/download'
referer='http://powerbot.org'
filename='RSBot.jar'
curl -GL -e $referer -A "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19" -o $filename $download_page
# Well you could also add the line to add the line for start the bot after download
# java -jar $filename
@riston
riston / lines.sh
Created July 4, 2012 15:52
Source file line counter
find . -type f -name "*.java" -exec wc -l {} \; | awk '{total += $1} END{print total}'
@riston
riston / DraynorNet.java
Created July 5, 2012 19:30
Fishing script
package org.jurka.fishing;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.powerbot.concurrent.Task;
@riston
riston / ChickenFight.java
Created July 6, 2012 21:28
Falador Chicken Killer
package org.jurka.fighting;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import org.powerbot.concurrent.Task;
import org.powerbot.concurrent.strategy.Condition;
import org.powerbot.concurrent.strategy.Strategy;
import org.powerbot.game.api.ActiveScript;
@riston
riston / irc.js
Created September 26, 2012 10:01
IRC bot in Node.js
var net = require('net')
, util = require('util')
, exec = require('child_process').exec;
var options = {
PORT: 6667
, HOST: 'irc.freenode.net'
, NICK: 'Miska'
, CHANNELS: [ '#node.js', '#javascript', '#randomChan' ]
, USER: {
//first, checks if it isn't implemented yet
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
@riston
riston / asyncCalc.js
Created August 13, 2013 07:15
Node.js makind calculation async
function sum(a, b, cb) {
return process.nextTick(function() {
return cb(null, a + b);
});
}
sum(32, 43, function(err, res) {
console.log(res);
});