Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Looking for my next project...

Guy Vider TravelingTechGuy

💭
Looking for my next project...
View GitHub Profile
@TravelingTechGuy
TravelingTechGuy / NodeSqlite.js
Created Aug 1, 2011
Using SQLite from Node.js
View NodeSqlite.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 Aug 27, 2011
Display JavaScript function name
View DisplayJSFunctionName1.js
var fname = /^function\s+([^(]+)/.exec(arguments.callee.toString())[1];
console.log(fname);
//alert(fname);
@TravelingTechGuy
TravelingTechGuy / DisplayJSFunctionName2.js
Created Aug 27, 2011
Display JavaScript function name
View DisplayJSFunctionName2.js
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 Aug 27, 2011
Create a fuzzy, verbal clock
View fuzzyclock.rb
#!/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 Aug 28, 2011
Test JSON service using python
View JSONTest.py
import urllib2
import json
url = '<INSERT URL>'
data = {
'aaa': '7673336666',
'bbb': ['4544444445','xxxxxxx','334tttt890'],
'ccc': {
'ddd': 'on',
'eee': 5
View npm-install.sh
#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 Jun 12, 2012
Post values to an HTML page using jQuery
View InstantPost.js
(
$("<form/>",{"action":"index.php","method":"post"}).append(
$("<input/>", {"type":"hidden", "name":"logout", "value":"1"})
)
).submit();
@TravelingTechGuy
TravelingTechGuy / curl.php
Created Sep 7, 2012
Posting to service using CURL from PHP
View curl.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);
View php54_php53_pear_macports.markdown

##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 Dec 14, 2015
create ad-hoc form and submit it - using jQuery
View adhoc form.js
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();
}
You can’t perform that action at this time.