Skip to content

Instantly share code, notes, and snippets.

@Krishna
Krishna / gist:99829
Created April 22, 2009 14:42
vardump for Lua (modified from Lua Gems)
--
-- vardump
-- original verstion by Tobias Sulzenbruck and Christoph Beckmann
-- source: Lua Gems, page 29
-- modifications: Krishna Kotecha
--
--[[
value - the value to dump
@hashmal
hashmal / gist:874792
Created March 17, 2011 17:54
[Lua] Print table contents recursively
-- Print contents of `tbl`, with indentation.
-- `indent` sets the initial level of indentation.
function tprint (tbl, indent)
if not indent then indent = 0 end
for k, v in pairs(tbl) do
formatting = string.rep(" ", indent) .. k .. ": "
if type(v) == "table" then
print(formatting)
tprint(v, indent+1)
else
@codification
codification / graphite-client.py
Last active April 29, 2019 17:21
Graphite client in python
import time
import socket
def collect_metric(name, value, timestamp):
sock = socket.socket()
sock.connect( ("localhost", 2003) )
sock.send("%s %d %d\n" % (name, value, timestamp))
sock.close()
def now():
return int(time.time())
@nrk
nrk / command.txt
Created April 2, 2012 19:19
Using ffprobe to get info from a file in a nice JSON format
ffprobe -v quiet -print_format json -show_format -show_streams "lolwut.mp4" > "lolwut.mp4.json"
@bricef
bricef / AES.c
Last active March 4, 2023 11:29
A simple example of using AES encryption in Java and C.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* MCrypt API available online:
* http://linux.die.net/man/3/mcrypt
*/
#include <mcrypt.h>
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@jastkand
jastkand / ability.rb
Created September 22, 2012 09:42 — forked from watson/ability.rb
Active Admin CanCan integration with shared front/backend User model and multi-level autherization
# app/models/ability.rb
# All front end users are authorized using this class
class Ability
include CanCan::Ability
def initialize(user)
user ||= AdminUser.new
case user.role
when "admin"
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active April 19, 2024 11:00
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@zmaril
zmaril / collatz.clj
Created February 1, 2013 02:26
Collatz fun
(ns collatz.core)
(defn collatz
"Given n, it returns n/2 if it's even or n*3+1 if it's odd."
[n]
(if (even? n)
(/ n 2)
(+ (* 3 n) 1)))
(declare count-steps-of-collatz)
@adnan-i
adnan-i / angular-timeout.html
Last active March 16, 2017 11:55 — forked from orjan/angular-timeout.html
Workaround for $httpProvider.defaults As discussed here http://stackoverflow.com/a/15020611/1095616, it is not possible to set default timeout in $httpProvider. This gist offers a workaround.
<!doctype html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
</head>
<body>
<div ng-controller="TodoCtrl">
<button ng-click="beQuickOrBeDead()">Fetch with 100ms timeout</button>
<button ng-click="neverEndingStory()">Fetch with default timeout</button>