This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Copyright (c) 2013, Manu Manjunath | |
All rights reserved. | |
Redistribution and use of this program in source/binary forms, with or without modification are permitted. | |
Link to this gist is preferred, but not a condition for redistribution/use. | |
*/ | |
function parse_csv_file($csvfile) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Copyright (c) 2012, Manu Manjunath | |
All rights reserved. | |
Redistribution and use of this program in source/binary forms, with or without modification are permitted. | |
Link to this gist is preferred, but not a condition for redistribution/use. | |
*/ | |
function mail_with_attachments($to, $subject, $message, Array $filepaths, $from = null, $replyto = null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Quick replacement to date() function to handle the 'u' format specifier (for microseconds) | |
* @param string $format Date format string - the same format string you would pass to date() function | |
* @param float $timestamp [optional] Unix timestamp with microseconds - Typically output of <b>microtime(true)</b> | |
* @return string Formatted string | |
*/ | |
function date_with_micro($format, $timestamp = null) { | |
if (is_null($timestamp) || $timestamp === false) { | |
$timestamp = microtime(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
''' | |
Command-line script to get stock price (in USD and local currency) | |
Prerequisite: | |
Python 2.7 | |
Installation: | |
Copy this script to /usr/bin or /bin. | |
Usage: | |
$ stock ZNGA | |
This will get you stock price for company with stock symbol 'ZNGA' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
""" | |
Description: | |
Command-line tool to validate an email address. | |
After verifying e-mail address by pattern matching, checks the validity with the SMTP server. | |
Usage: | |
./email-verify [email protected] | |
# (c) 2013 Manu Manjunath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Converts an RSS feed string to clean, cross-browser HTML string | |
* (Output will be XHTML compliant if the feed source is XHTML compliant) | |
* @param string $rss_feed_xml_str RSS feed (XML) string | |
* @return string HTML string on success, <b>false</b> on failure. | |
*/ | |
function rss_to_html($rss_feed_xml_str) { | |
$feed_html = false; | |
$feed = simplexml_load_string($rss_feed_xml_str, null, LIBXML_NOCDATA); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import sys | |
import csv | |
home = os.getenv("HOME") | |
known_hosts_path = home+'/.ssh/known_hosts' | |
known_hosts_optimized_path = home+'/.ssh/known_hosts_optimized' | |
d = {} | |
csvfile = open(known_hosts_path, 'r') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Read entire contents of given URL as a string. Optionally, get headers as well in an easily accessible array. | |
* @param string $url URL to fetch data from | |
* @param mixed $params Parameters to the URL, typically an array. In case of POST, can be a string | |
* @param string $method HTTP method - can be 'GET' (default) or 'POST' | |
* @param bool $include_headers Should response headers be included? | |
* @return mixed Contents of the webpage as a string. Returns <i>false</i> in case of failure. If parameter <b>$include_headers</b> is <i>true</i>, returns an <i>array</i> containing response code, response headers and response body. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('GOOGLE_OAUTH2_CLIENT_ID', 'client id'); // this will be of form "<number>.apps.googleusercontent.com" | |
define('GOOGLE_OAUTH2_CLIENT_SECRET', 'client secret'); // this will be a base64 string | |
define('GOOGLE_OAUTH2_REDIRECT_URI', 'redirect url'); // This URL should be registered under "Redirect URIs" | |
define('YOUR_DOMAIN', 'your domain'); // your domain | |
define('OAUTH2_SESSION_DURATION', 90); //in seconds | |
require __DIR__ . "/url_get_contents.php"; // Use https://gist.github.com/m-manu/7462652 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package manu.sandbox.utils; | |
import java.util.Set; | |
public interface ScoredSet<T extends Comparable<T>> extends Set<T>, Cloneable { | |
interface ElementWithScore<T> { | |
T getElement(); | |
Double getScore(); | |
} |
OlderNewer