Skip to content

Instantly share code, notes, and snippets.

@damienalexandre
damienalexandre / tool.php
Created October 3, 2011 09:47
Download large file from the web via php
<?php
/**
* Download a large distant file to a local destination.
*
* This method is very memory efficient :-)
* The file can be huge, PHP doesn't load it in memory.
*
* /!\ Warning, the return value is always true, you must use === to test the response type too.
*
* @author dalexandre
@xeoncross
xeoncross / tf-idf.php
Created October 10, 2011 15:51
tf-idf Value (for Keywords)
These weights are often combined into a tf-idf value, simply by multiplying them together. The best scoring words under tf-idf are uncommon ones which are repeated many times in the text, which lead early web search engines to be vulnerable to pages being stuffed with repeated terms to trick the search engines into ranking them highly for those keywords. For that reason, more complex weighting schemes are generally used, but tf-idf is still a good first step, especially for systems where no one is trying to game the system.
There are a lot of variations on the basic tf-idf idea, but a straightforward implementation might look like:
<?php
$tfidf = $term_frequency * // tf
log( $total_document_count / $documents_with_term, 2); // idf
?>
It's worth repeating that the IDF is the total document count over the count of the ones containing the term. So, if there were 50 documents in the collection, and two of them contained the term in question, the IDF would be 50/2 = 25. To be accurate, we s
@MarcelloDuarte
MarcelloDuarte / alarm.php
Created November 2, 2011 06:24
My improvised PHP alarm
<?php
date_default_timezone_set('Europe/London');
$alarm = '06:00';
$musicFileToPlay = '~/Music/4\ non\ blondes/1-01\ Train.mp3';
$open = 'open'; // change this to what is the command in you OS. This works for MacOSX
while (true) {
@ryankinal
ryankinal / css-links.md
Created November 10, 2011 21:49
Useful CSS links for easy reference
@timw4mail
timw4mail / JSObject.php
Created November 30, 2011 20:22
PHP Class for javascript-like objects
<?php
/**
* JSObject
*
* Class for creating object-literal-like contstructs in PHP
*/
class JSObject {
/**
@mklabs
mklabs / bootstrap-plugins.txt
Created December 2, 2011 11:23
h5bp + twitter bootstrap integration
bootstrap-tooltip.js
bootstrap-popover.js
bootstrap-alert.js
bootstrap-button.js
bootstrap-carousel.js
bootstrap-collapse.js
bootstrap-dropdown.js
bootstrap-modal.js
bootstrap-scrollspy.js
bootstrap-tab.js
@Plutor
Plutor / limitedminheap.php
Created December 16, 2011 18:37
A min-max heap and a limited-size min heap (in PHP)
<?php
include 'minmaxheap.php';
/* A min-heap that will restrict itself to a maximum of some number of values.
* Implemented internally as a min-max heap.
*
* Public API:
* - Contructor takes a number, used as the maximum number of values allowed on the heap
* - count() - returns the number of elements on the heap
@xeoncross
xeoncross / simple.ses.php
Created January 4, 2012 04:19
Simple SendEmail wrapper for Amazon SES API (does not support SendRawEmail)
<?php
class SES
{
public $accessKey = NULL;
public $accessKeyID = NULL;
public $host = 'https://email.us-east-1.amazonaws.com/';
public $userAgent = 'Test SES Class / v1.0';
public $data = array();
@zonca
zonca / ephemradec.py
Created January 24, 2012 21:46
PyEphem convert Azimuth/Elevation to RA/Dec
import datetime
import time
import numpy as np
import ephem
az = np.radians(6.8927)
el = np.radians(-60.7665)
lon = -1 * np.radians(109 + 24/60. + 53.1/60**2)
lat = np.radians(33 + 41/60. + 46.0/60.**2)
@boucher
boucher / gist:1750368
Created February 6, 2012 07:07 — forked from saikat/gist:1084146
Stripe sample checkout form
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Stripe Sample Form</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.min.js"></script>
<script type="text/javascript" src="https://js.stripe.com/v1/"></script>
<script type="text/javascript">