Skip to content

Instantly share code, notes, and snippets.

@freshteapot
freshteapot / gist:1712454
Created January 31, 2012 19:37
Using zeptos within Titanium with mustache.js
<html>
<head>
<script type="text/javascript" src="/html/js/zepto.min.js"></script>
<script>
$(document).ready(function(){
$("table").live('click', function (event){
event.stopPropagation();
var e = event.target;
Ti.API.info(e.tagName);
if (e.tagName.toLowerCase() === "span") {
@freshteapot
freshteapot / gist:4174469
Created November 30, 2012 08:13
Example of using php and libevent to processs a file at the command line by pipping it to the file.
a,b,c
d,e,f
---
<?php
global $writer;
$fileName = "./new.csv";
unlink($fileName);
$writer = fopen($fileName, "a+");
@freshteapot
freshteapot / sample.streamfile.php
Last active December 12, 2015 05:18
Sample of streaming data to a server. - Make sure php://input has not been used first. - Start with this then work it into your code so you know it works. - The client end, should returns small amounts for memory_get_usage even when you have a very large file.
<?php
echo memory_get_usage() . "\n";
$fileName = "/tmp/postedData";
$f = fopen($fileName, "w");
$s = fopen("php://input", "r");
while($kb = fread($s, 1024)) {
fwrite($f, $kb, 1024);
}
fclose($f);
@freshteapot
freshteapot / deep_sorting_by_attributes.js
Last active December 15, 2015 13:49
A little underscore magic to sort an array of objects by a nested value "score.high".
var a = _.chain(items)
.sortBy(function(entry){
return parseInt(entry['score']['high']);
})
.map(function(entry){
return entry;
})
.reverse()
.value();
return a;
@freshteapot
freshteapot / config.js
Created March 29, 2013 21:43
A sample of the requirejs config I am using.
/*global require*/
'use strict';
// Require.js allows us to configure shortcut alias
require.config({
baseUrl: 'js',
// The shim config allows us to configure dependencies for
// scripts that do not call define() to register a module
shim: {
underscore: {
@freshteapot
freshteapot / Vagrantfile for ceph
Created November 8, 2013 01:06
Based on: http://www.sebastien-han.fr/blog/2013/04/22/play-with-ceph-vagrant-box/ This version, at least worked for me using the "2" format.
Vagrant.configure("2") do |config|
config.vm.define :ceph do |role|
role.vm.box = "big-ceph"
role.vm.network :private_network, ip: "192.168.251.100"
role.vm.hostname = "ceph"
end
config.vm.define :client do |role|
role.vm.box = "ubuntu1304"
@freshteapot
freshteapot / gist:7578490
Created November 21, 2013 09:22
Basic Vagrantfile using raring.
# -*- mode: ruby -*-
# vi: set ft=ruby :
$build_script = <<SCRIPT
echo "Hello Vagrant World"
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu-raring"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/raring/current/raring-server-cloudimg-amd64-vagrant-disk1.box"
@freshteapot
freshteapot / gist:7886835
Created December 10, 2013 07:14
Sample curl on how to grab xml from netflix. Why? Because I want to read the translation.
curl 'http://so1.akam.nflximg.com/soa2/393/247283393.dfxp?v=1&e=1386475130&t=vNqnSQmaoj4d19LaUQzEJVa_VhM&random=918284700' -H 'Pragma: no-cache' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Host: so1.akam.nflximg.com' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36' -H 'Accept: */*' -H 'Referer: http://movies.netflix.com/WiPlayer?movieid=70128675&trkid=13462100&t=The%2BAmerican&tctx=-99%2C-99%2C6e92be96-1318-4100-912e-a651f7a2b7d2-1567203' -H 'Connection: keep-alive' -H 'Cache-Control: no-cache' --compressed > the.american.70128675.xml
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# forked by Gianluca Guarini
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep -E --quiet "$1" && eval "$2"
}
@freshteapot
freshteapot / example.md
Last active January 20, 2017 13:29
Example of how to pre build vcl backends for use with variables from varnishtest.

Using varnishtest with semi dynamic test servers.

  • s1_addr and s1_port exist because the server name is s1.
  • using shell, we are able to drop to the shell to process the variables varnishtest made, process them and pipe them into a vcl that is expected later.
# varnishtest.vtc

server s1 {
  rxreq