Skip to content

Instantly share code, notes, and snippets.

View ghalusa's full-sized avatar
🤓
Geekin'

Goran Halusa ghalusa

🤓
Geekin'
View GitHub Profile
@ghalusa
ghalusa / gist:5485982
Last active February 25, 2020 21:48
Install node.js on a raspberry pi
wget http://nodejs.org/dist/v0.10.5/node-v0.10.5-linux-arm-pi.tar.gz
cd /usr/local
sudo tar xzvf ~/node-v0.10.5-linux-arm-pi.tar.gz --strip=1
vi ~/.bash_aliases
export PATH=$PATH:/usr/local/bin/node
bash
node -v
@ghalusa
ghalusa / random_rows
Created May 8, 2013 03:43
Efficiently Selecting Random Rows From a MySQL Table
public function getRandomRecords()
{
// Select the first id in the target table
$statement = $this->db->prepare("SELECT some_id
FROM table_name
ORDER BY some_id ASC LIMIT 1");
$statement->execute();
$lowest_id = $statement->fetch(PDO::FETCH_ASSOC);
// Select the last id in the target table
The objective of this post is to get you from absolutely nothing, to a fully functional nodejs environment.
Software used: Ubuntu 11.10, Nodejs v0.6.12, Nginx, MongoDB, Redis, and NPM modules.
1. Download and install the latest version of Ubuntu: http://www.ubuntu.com/download (don't select any extra items to install when prompted)
2. Once you are logged in and are at your Ubuntu command prompt, install the necessary software you will need:
a. sudo apt-get install openssh-server
b. sudo apt-get install libssl-dev
c. sudo apt-get install git
d. sudo apt-get install g++
e. sudo apt-get install make
@ghalusa
ghalusa / parse_a_rendered.php
Created May 16, 2013 11:36
Parsing anchors in rendered html with php
<?php
$url = "http://www.imdb.com/movies-in-theaters/";
$input = @file_get_contents($url) or die("Could not access file: $url");
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $input, $matches)) {
// $matches[2] = array of link addresses
// $matches[3] = array of link text - including HTML code
echo "<pre>";
var_dump($matches[2]);
echo "</pre>";
@ghalusa
ghalusa / node-load-tweet.js
Created May 17, 2013 19:59
node-load-tweet
/**
* Script dependencies
*/
var twitter = require('ntwitter');
var settings = require('./config.js');
var exec = require('child_process').exec;
var twit = new twitter({
consumer_key: settings.consumer_key ,
@ghalusa
ghalusa / ampps_debug_mac.md
Last active December 1, 2020 01:39
Getting AMPPS to fully run after installation on Mac OS X 10.8.x
@ghalusa
ghalusa / org.mongo.mongod.plist
Created September 21, 2014 23:39
MongoDB startup plist file for Mac OS X
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.mongo.mongod</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
@ghalusa
ghalusa / interfaces
Last active August 29, 2015 14:06
Configuring WiFi on a Raspberry Pi Running Raspbian (Debian)
# Open the networking configuration file using your favorite editor (vi, nano, etc....)
sudo vi /etc/network/interfaces
# Enter the following:
auto lo
iface lo inet loopback
iface eth0 inet dhcp
@ghalusa
ghalusa / gist:43d96e8bcf4fc668f8be
Created October 21, 2014 01:21
Bootable USB OS X 10.10 Yosemite Install Using createinstallmedia
# Create a bootable OS X 10.10 Yosemite install drive on a USB flash drive using createinstallmedia
sudo /Volumes/Macintosh\ HD/Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ Yosemite.app --nointeraction
@ghalusa
ghalusa / mongodb_update_multiple
Created October 29, 2014 00:54
Update Multiple MongoDB Documents in a Collection
db.domains.update( { username: "someuser@gmail.com" }, { $set: { something: 0 } }, { multi: true } )