Skip to content

Instantly share code, notes, and snippets.

View xtianjohns's full-sized avatar

Christian Johns xtianjohns

View GitHub Profile
@staltz
staltz / introrx.md
Last active April 29, 2024 09:25
The introduction to Reactive Programming you've been missing
@jeffjohnson9046
jeffjohnson9046 / percent-filter.js
Last active September 4, 2020 23:25
Format percentages in AngularJS
// In app.js or main.js or whatever:
// var myApp = angular.module('askchisne', ['ngSanitize', 'ngAnimate', 'ui.bootstrap', 'ui.bootstrap.tpls']);
// This filter makes the assumption that the input will be in decimal form (i.e. 17% is 0.17).
myApp.filter('percentage', ['$filter', function ($filter) {
return function (input, decimals) {
return $filter('number')(input * 100, decimals) + '%';
};
}]);
@greenlion
greenlion / gist:9244835
Created February 27, 2014 05:20
A sample data generator for web traffic time series log file
<?php
/* a sample of traffic data from the real website, deduplicated and REST URLs digested */
$traffic = unserialize(file_get_contents('seed.dat')) or die('Could not unserialize seed.dat');
/* 20% chance by default */
function chance($greater_than=20, $bottom=1, $top = 100) {
$toss = mt_rand($bottom, $top);
if($greater_than >= $toss) return true; else return false;
}
@jjmaestro
jjmaestro / whisper-calculator.py
Last active November 26, 2019 07:13
whisper-calculator.py: Calculates the size of the whisper storage for the given retention (in frequency:history format)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def archive_to_bytes(archive):
def to_seconds(s):
SECONDS_IN_A = {
's': 1,
'm': 1 * 60,
'h': 1 * 60 * 60,
@tanepiper
tanepiper / HighResolutionTimer.js
Created December 5, 2012 13:47
A high resolution timer, set the tick duration (default 1s) and callback to be actioned on each tick - accurate to within ~1-5ms per tick and compensates automatically for drift over time.
var HighResolutionTimer = window.HighResolutionTimer = window.HighResolutionTimer || (function() {
var HighResolutionTimer = function(options) {
this.timer = false;
this.total_ticks = 0;
this.start_time = undefined;
this.current_time = undefined;
@mshafrir
mshafrir / states_hash.json
Created May 9, 2012 17:05
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@manast
manast / interval.js
Last active November 15, 2023 22:08
Accurate Javascript setInterval replacement
function interval(duration, fn){
var _this = this
this.baseline = undefined
this.run = function(){
if(_this.baseline === undefined){
_this.baseline = new Date().getTime()
}
fn()
var end = new Date().getTime()