Skip to content

Instantly share code, notes, and snippets.

View dpogorzelski's full-sized avatar

Dawid Pogorzelski dpogorzelski

View GitHub Profile
@dpogorzelski
dpogorzelski / gist:2702690
Created May 15, 2012 15:33
Get LDAP users from WMS
require 'net/ldap'
ldap = Net::LDAP.new
ldap.host = "192.168.222.154"
ldap.port = 389
ldap.auth "cn=netreader,dc=wildix", "wildix"
if !ldap.bind
puts "Connection failed"
end
@dpogorzelski
dpogorzelski / completion.rb
Created May 30, 2012 23:18
Command and arguments completion with readline.
COMMANDS = {
'collect' => ['info', 'info2'],
'watch' => ['watchvalue_1', 'watchvalue_2']
}
comp = proc do |s|
if Readline.line_buffer =~ /#{COMMANDS.keys} /
COMMANDS.values_at("#{Readline.line_buffer.gsub(/ .*/,'')}").flatten.grep(/^#{Regexp.escape(s)}/)
else
COMMANDS.keys.grep(/^#{Regexp.escape(s)}/)
@dpogorzelski
dpogorzelski / console.rb
Created June 8, 2012 23:28 — forked from JohnMurray/console.rb
An example console from my geofence-server-example project
#!/usr/bin/env ruby
# require all the necessary files
$: << ::File.expand_path('../src', __FILE__)
require 'app'
require 'geofence'
# at this point bundler should be setup and the :development group
# should have been included. However, just to be sure, I'm going to
# include bundler again and require the console group.
@dpogorzelski
dpogorzelski / twitter-oauth-pin.html
Created July 18, 2012 22:18 — forked from funkatron/twitter-oauth-pin.html
A simple example of PIN-based oauth flow with Twitter and jsOAuth
<!DOCTYPE html>
<html>
<head>
<!--
A simple example of PIN-based oauth flow with Twitter and jsOAuth.
This is mostly based on/copied from <http://log.coffeesounds.com/oauth-and-pin-based-authorization-in-javascri>.
Get jsOAuth at <https://github.com/bytespider/jsOAuth/downloads>
@dpogorzelski
dpogorzelski / app.rb
Created April 15, 2013 09:12
Time your Sinatra methods
helpers do
def measure (&block)
start_time = Time.now
val = yield
end_time = Time.now
logger.info "Time elapsed for #{request.path_info} #{(end_time - start_time)*1000} milliseconds"
val
end
end
"use strict";
var app = angular.module('charts',['charts.services', 'charts.directives']);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/', {
controller: 'MenuCtrl',
templateUrl:'/users.html'
}).
var Person = function(name, surname, gender){
this.name = function(){
console.log('instance function ' + name);
};
this.surname = surname;
this.gender = gender;
};
Person.prototype.getGender = function(){
@dpogorzelski
dpogorzelski / gunzip.js
Created May 21, 2013 15:53
Read http request's body which has a gzip content encoding (node.js);
var https = require('https');
var gunzip = require('zlib').createGunzip();
var options = {
host: 'api.stackexchange.com',
path: '/2.1/info?site=stackoverflow'
};
https.get(options, function(res) {
var body = '';
@dpogorzelski
dpogorzelski / neural.js
Last active December 19, 2015 02:29
Neural network implementation based on 'Introduction to the Math of Neural Networks' book. Not complete yet.
Network = function(input, hidden, output) {
if (arguments.length !== 3) {
console.log('Check your arguments, quitting...');
process.exit();
}
this.B1 = 1.0;
this.B2 = 1.0;
for (var i = 1; i <= input; i++) {
this['I' + i] = 0;