Skip to content

Instantly share code, notes, and snippets.

View TravelingTechGuy's full-sized avatar
💭
Looking for my next project...

Guy Vider TravelingTechGuy

💭
Looking for my next project...
View GitHub Profile
@TravelingTechGuy
TravelingTechGuy / NodeSqlite.js
Created August 1, 2011 05:01
Using SQLite from Node.js
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('guy.sqlite'); //':memory:'
db.serialize(function() {
db.get("SELECT name FROM sqlite_master WHERE type='table' AND name='lorem'", function(error, row) {
if (row !== undefined) {
console.log("table exists. cleaning existing records");
db.run("DELETE FROM lorem", function(error) {
if (error)
console.log(error);
@TravelingTechGuy
TravelingTechGuy / DisplayJSFunctionName1.js
Created August 27, 2011 10:28
Display JavaScript function name
var fname = /^function\s+([^(]+)/.exec(arguments.callee.toString())[1];
console.log(fname);
//alert(fname);
@TravelingTechGuy
TravelingTechGuy / DisplayJSFunctionName2.js
Created August 27, 2011 10:32
Display JavaScript function name
function reportName() {
var fname = /^function\s+([^(]+)/.exec(reportName.caller.toString())[1];
console.log(fname);
}
function MyFunctionHAsALongName() {
reportName();
//Do some stuff
}
@TravelingTechGuy
TravelingTechGuy / fuzzyclock.rb
Created August 27, 2011 22:51
Create a fuzzy, verbal clock
#!/usr/bin/env ruby
hour, minute = Time.now.strftime('%I').to_i, Time.now.min
ones = %w{ nil one two three four five six seven eight nine }
teens = %w{ ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen }
tens = %w{ nil nil twenty thirty forty fifty }
minute_str = case minute
when 0 then 'o-clock'
when 1..9 then "o-#{ones[minute]}"
@TravelingTechGuy
TravelingTechGuy / JSONTest.py
Created August 28, 2011 06:49
Test JSON service using python
import urllib2
import json
url = '<INSERT URL>'
data = {
'aaa': '7673336666',
'bbb': ['4544444445','xxxxxxx','334tttt890'],
'ccc': {
'ddd': 'on',
'eee': 5
@TravelingTechGuy
TravelingTechGuy / npm-install.sh
Created November 17, 2011 19:59
Install npm on a mac
#To get the sudo password prompt
sudo ls
#Pay attention - the sudo is on the 'sh', not the 'curl'
curl http://npmjs.org/install.sh | sudo sh
@TravelingTechGuy
TravelingTechGuy / InstantPost.js
Created June 12, 2012 17:41
Post values to an HTML page using jQuery
(
$("<form/>",{"action":"index.php","method":"post"}).append(
$("<input/>", {"type":"hidden", "name":"logout", "value":"1"})
)
).submit();
@TravelingTechGuy
TravelingTechGuy / curl.php
Created September 7, 2012 21:47
Posting to service using CURL from PHP
public static function callService($url, $postData) {
if(stripos($_SERVER['HTTP_HOST'], "localhost") !== FALSE)
$postData .= "&XDEBUG_SESSION_START=netbeans-xdebug";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // return into a variable
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REMOTE_ADDR']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

##Given Apache 2 and MySQL are already installed.

#Update MacPorts sudo port selfupdate;sudo port -u upgrade outdated

#Install PHP 5.4.* sudo port install php54 php54-apache2handler ##Activate Apache Module cd /opt/local/apache2/modules

@TravelingTechGuy
TravelingTechGuy / adhoc form.js
Last active December 14, 2015 09:59
create ad-hoc form and submit it - using jQuery
var postForm = function(destination, fields) {
var form = $("<form/>",{"action":destination,"method":"post"});
$.each(fields, function(name, value) {
form.append($("<input/>", {"type":"hidden", "name":name, "value":value}));
});
//for this to work in FF, form must be appended to body - not necessary in WebKit
$("body").append(form);
form.submit();
}