Skip to content

Instantly share code, notes, and snippets.

for ip in $(gseq 1 254); do ping -c 1 192.168.1.$ip>/dev/null; [ $? -eq 0 ] && echo "192.168.1.$ip UP" || : ; done
var object = {};
function fn(){
return this;
}
assert( fn() == this, "The context is the global object." );
assert( fn.call(object) == object, "The context is changed to a specific object." );
@loganlinn
loganlinn / vBulletinUser.php
Created January 23, 2011 19:41
Forces a login into vBulletin (4.x) using just a username
<?php
class vBulletinUser{
public static function login($username, $remember_me = false){
chdir(VB_ROOT_PATH);
require_once('./global.php');
require_once(DIR . '/includes/functions_login.php');
global $vbulletin,$vbphrase;
$remember_me = $remember_me ? true : false; //force to true or false value
$vbulletin->userinfo = $vbulletin->db->query_first("SELECT userid, usergroupid, membergroupids, infractiongroupids,
username, password, salt FROM ".TABLE_PREFIX."user WHERE username = '".
@loganlinn
loganlinn / php_reference_bug.php
Created March 10, 2011 06:37
Not-so-obvious PHP behavior when using for-each by reference and value with same variable name. (contrived example)
<?php
$foo = array(1, 2, 3);
foreach($foo as &$bar) {
$bar *= $bar;
}
foreach($foo as $bar){
echo "The square is ", $bar, "\n";
}
@loganlinn
loganlinn / php_callstatic_reference.php
Created April 17, 2011 19:26
PHP __callStatic by Reference
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
class Test {
private static $_inst = array();
public static function & __callStatic ($name, $args) {
if (!isset(self::$_inst[$name])){
echo "Created \n";
self::$_inst[$name] = (object) "test";
@loganlinn
loganlinn / gh.rb
Created August 12, 2011 21:39
Quick script to open GitHub pages for the repository in the working directory.
#!/usr/bin/ruby
require 'rubygems'
require 'grit'
begin
r = Grit::Repo.new Dir.pwd
rescue
puts "Did not detect git repository"
exit
@loganlinn
loganlinn / exercise1-1.scm
Created August 16, 2011 21:01
Exercise 1.1 from SICP
; f(n) = n, n < 3
; = f(n-1) + 2f(n-2) + 3f(n-3), n >= 3
(define (f-iter n)
(fp 2 1 0 n 3))
(define (fp a b c n i)
(if (= n i)
(+ a (* 2 b) (* 3 c))
(fp (+ a (* 2 b) (* 3 c))
a
@loganlinn
loganlinn / hubspot_interview_question.js
Created September 12, 2011 16:37
find 2nd largest number given array
// second_largest (array of numbers)
// returns 2nd largest number in array
function second_largest(numbers) {
if(numbers.length < 2){
return numbers[0];
}
var n,
first_largest = numbers[0],
second_largest = numbers[1];
@loganlinn
loganlinn / nltk_download.zsh
Created January 17, 2012 17:34
Downloads Natural Language Processing with Python book (http://www.nltk.org/book)
#!/usr/bin/env zsh
for i in {0..12}; do
if [[ $i -lt 10 ]]; then
wget http://nltk.googlecode.com/svn/trunk/doc/book/ch0$i.html
else
wget http://nltk.googlecode.com/svn/trunk/doc/book/ch$i.html
fi
done
#require 'awesome_print'
require 'json'
module OMGWidgets ; end
module OMGWidgets::ActivityPartition
class DirCounter
attr_accessor :parent, :name, :hits, :children, :files
def initialize(parent=nil)
@hits = 0