Skip to content

Instantly share code, notes, and snippets.

View padenot's full-sized avatar
🦊
counting bytes

Paul Adenot padenot

🦊
counting bytes
View GitHub Profile
@padenot
padenot / stream.js
Created October 29, 2011 16:33
How to serve media on node.js
var http = require('http');
var path = require('path');
var fs = require('fs');
var AUDIOFILE = "./audio.ogg";
function serveWithRanges(request, response, content) {
var range = request.headers.range;
var total = content.length;
var parts = range.replace(/bytes=/, "").split("-");

Install netlify:

npm install -g netlify-cli

Set it up like so, this will open a few web pages and create a netlify account with github login, authorize netlify, setup the github hook for deploy, etc.:

repositories/ringbuf.js::master$ netlify init
Logging into your Netlify account...
Opening https://app.netlify.com/authorize?response_type=ticket&ticket=e527b77c4d5c2a95a57c063ccb193459
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef __SANITIZE_ADDRESS__
#define ALLOC_STACK(ptr) __asan_describe_address(ptr)
#else
#define ALLOC_STACK(ptr) fprintf(stderr, \
"Do an ASAN build to get allocation stacks.\n");
#endif
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <errno.h>
int main(int argc, char *argv[])
# Setup and packages
```sh
sudo aptitude install icecast2 gstreamer0.10-pulseaudio gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly-multiverse gstreamer-tools pavucontrol
```
Remember the password when setting up `icecast2` (when prompted by the install
script), because we will use it later on.
# Setup pulse
@padenot
padenot / pdfwc
Created November 10, 2011 23:35
pdfwc
#!/bin/sh
if [ $# -eq 0 ]
then
echo "$(basename $0) [-w|-c|-l|-L]? file.pdf+"
echo "\t-w : count words"
echo "\t-c : count characters"
echo "\t-l : count lines"
echo "\t-L : maximum line length"
exit 1
@padenot
padenot / timelapse.sh
Created September 28, 2011 14:02
A timelapse script
#!/usr/bin/zsh -x
mkdir timelapse_frames
cd timelapse_frames
# in seconds
if [ -z $1 ]
then
duration=10
else
duration=$1
fi
@padenot
padenot / timelapse.sh
Created September 28, 2011 14:01
Timelapse script
#!/usr/bin/zsh -x
mkdir timelapse_frames
cd timelapse_frames
# in seconds
if [ -z $1 ]
then
duration=10
else
duration=$1
fi
@padenot
padenot / gist:1002059
Created June 1, 2011 09:56
How to save a file from js (from tiddlywiki code)
function mozillaSaveFile(filePath,content)
{
if(window.Components) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filePath);
if(!file.exists())
file.create(0,0664);
var out = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
@padenot
padenot / gist:875097
Created March 17, 2011 20:48
Du blocage de l'internet pendant quelque minutes, ou comment gagner en productivité
#!/bin/sh
time=$(zenity --text="On bloque le net combien de temps ?" --scale --value=60 --min-value=1 --max-value=600)
echo $time
network_interface=$(ifconfig | grep Link | tr -s ' ' | cut -d ' ' -f1)
for i in $network_interface
do