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
// Extract "GET" parameters from a JS include querystring | |
function getParams(script_name) { | |
// Find all script tags | |
var scripts = document.getElementsByTagName("script"); | |
// Look through them trying to find ourselves | |
for(var i=0; i<scripts.length; i++) { | |
if(scripts[i].src.indexOf("/" + script_name) > -1) { | |
// Get an array of key=value strings of params | |
var pa = scripts[i].src.split("?").pop().split("&"); |
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/env ruby | |
# | |
# Passenger management script | |
# By James Smith http://loopj.com | |
# Based heavily on a similar script by Jon Bettcher | |
# | |
# Check memory usage of all paseenger child process and kill if grows | |
# too large. | |
# |
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
#!/bin/bash | |
echo "SET autocommit=0; | |
SET unique_checks=0; | |
SET foreign_key_checks=0;" > backup.sql | |
mysqldump -u myuser --password=mypassword mydatabase >> backup.sql | |
echo "COMMIT;" >> backup.sql |
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 | |
''' | |
Copyright 2009, The Android Open Source Project | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 |
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
class MongoHelpers | |
# Sum over fields | |
def self.sum(collection, fields, group_by, conditions=nil) | |
map = <<-EOD | |
function() { | |
self = this; | |
key = {}; | |
if(group_by && group_by.length > 0) { | |
group_by.forEach(function (g) { |
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
# | |
# Requirements for js framework | |
# | |
# - Cache Page "chrome", javascripts, css, templates in app-cache | |
# - Optionally | |
# - Load json data from android/ios client (eg. android Parcelable data) | |
# - Load json data immediately from cache, if present | |
# - Load json data from http json endpoint, store to cache | |
# - Update view elements when associated model data changes (knockout.js?) |
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
# Example usage | |
AvatarCache = new RedisCache | |
keyPrefix: "userAvatar:" | |
expiry: 3600 | |
generator: (key, callback) -> | |
request "https://api.github.com/users/#{key}", (error, response, body) -> | |
if !error and response.statusCode == 200 | |
user = JSON.parse(body) | |
generate user.avatar_url |
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
# Usage: | |
# | |
# timer = AverageTimer.new | |
# my_loop do | |
# # Track an avent | |
# timer.event | |
# | |
# # Print the events per second (averaged over 5 seconds) | |
# puts timer.events_per_second(5) | |
# |
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
// Device memory data | |
ActivityManager activityManager = (ActivityManager) androidContext.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); | |
// Runtime data memory numbers are in bytes (dalvik process?) | |
int processors = runtime.availableProcessors(); | |
long totalMemory = runtime.totalMemory(); | |
long freeMemory = runtime.freeMemory(); | |
System.out.println(String.format("Runtime: %d processors, %d totalMemory (bytes), %d freeMemory (bytes)", processors, totalMemory, freeMemory)); | |
// Debug data (system wide) memory numbers are in bytes |
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
function getCurrentOpStats() { | |
intervals = [1,5,10,30] | |
waitingForLock = 0; | |
secsRunningStats = {}; | |
inProg = db.currentOp()["inprog"] | |
inProg.forEach(function (op) { | |
if(op["waitingForLock"]) { | |
waitingForLock += 1; | |
} |
OlderNewer