Skip to content

Instantly share code, notes, and snippets.

@itorres
itorres / ssha.js
Created June 18, 2012 06:10
node.js ssha hash generation and check functions intended for use with LDAP servers.
var crypto = require('crypto');
/*
* node.js ssha hash generation and check functions intended for use with LDAP servers.
*/
function ssha(cleartext, salt) {
var sum = crypto.createHash('sha1');
( typeof(salt) == 'undefined') ? salt = new Buffer(crypto.randomBytes(20)).toString('base64') : salt = salt;
sum.update(cleartext);
@itorres
itorres / solarize_gnome_terminal
Created August 6, 2013 16:41
Configure Solarized (http://ethanschoonover.com/solarized) in Gnome Terminal 3.8
#!/usr/bin/env ruby
#
# Configure Solarized (http://ethanschoonover.com/solarized) in
# Gnome Terminal 3.8
#
# Hacked away in a lazy summer afternoon by http://ignacio.torresmasdeu.name/
profile_dir="/org/gnome/terminal/legacy/profiles"
default_profile=`gsettings get org.gnome.Terminal.ProfilesList default`.strip.delete("'")
@itorres
itorres / getopt.py
Created October 1, 2014 02:46
YAPOP (Yet Another Python Option Parser)
def getopt(wat,default=None):
"""
getopt("flag") returns a bool
getopt("flag","default value") returns the next item in the argument list
Examples:
when calling "script -f filename":
getopt("-f","defaultname") would return "filename"
getopt("-v") would return False
when calling "script -v":
@itorres
itorres / gist:2b88920c18af52b686c8
Created October 5, 2014 14:25
A quick hack to get an object with the devices in firefoxosdevices.org.
function firefoxosdevicesIndex() {
var r = { 'd': {}, 's': {} };
devices = document.querySelectorAll(".ag-device");
for (var i = 0; i < devices.length; i++) {
var model = devices[i].querySelector(".ag-name").textContent.trim();
var specs = devices[i].querySelectorAll("dt");
r['d'][model] = {};
for (var j = 0; j < specs.length; j++) {
var spec = specs[j].textContent.trim(),
value = specs[j].nextSibling.textContent.trim();

Keybase proof

I hereby claim:

  • I am itorres on github.
  • I am itorres (https://keybase.io/itorres) on keybase.
  • I have a public key whose fingerprint is 2CCB 85E6 8AEC C336 5ADF 1C14 A728 61BC 6411 65EA

To claim this, I am signing this object:

@itorres
itorres / gist:e8f242e292689d1ae6c2
Created November 7, 2014 01:22
Count wrong registrations by IP in an asterisk logfile
# model:
# [Nov 4 12:26:52] NOTICE[416] chan_sip.c: Registration from '"x" <sip:[email protected]:5060>' failed for '1.2.3.4' - No matching peer found
awk '/failed for/ {count[$12]++}END{for (j in count) printf "%8i %s\n", count[j],j }' messages|sort -n
@itorres
itorres / flac2opus.py
Created December 10, 2014 10:53
Quick script to transcode a flac music collection to opus
#!/usr/bin/env python
import os
import sys
basedir = sys.argv[1]
for root, dirs, files in os.walk(basedir):
cmd = 'avconv -i "{infile}" -map 0:a -codec:a \
opus -b:a 48k -vbr on "{outfile}"'
print "Visiting", root
@itorres
itorres / 20160316-OCC-too-many-files-error
Created March 16, 2016 23:27
OCC FreeBSD errors for folders with > 50000 files
magellan:ownCloud$ owncloud --logfile -
03-17 00:00:25:862 101358 OCC::Application::setupLogging: "################## ownCloud ca_ES () 2.1.1"
03-17 00:00:25:862 101358 OCC::Application::setupTranslations: void OCC::Application::setupTranslations() Using "ca_ES" translation
03-17 00:00:25:864 101358 unknown: QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-itorres'
03-17 00:00:25:864 101358 OCC::SocketApi::SocketApi: SocketApi: server started, listening at "/tmp/runtime-itorres/ownCloud/socket"
03-17 00:00:25:864 101358 OCC::FolderMan::FolderMan: setting remote poll timer interval to 30000 msec
03-17 00:00:25:945 101358 OCC::FolderMan::setupFolders: * Setup folders from settings file
03-17 00:00:25:945 101358 OCC::Folder::checkLocalPath: Checked local path ok
03-17 00:00:25:946 101358 OCC::FolderMan::addFolderInternal: Adding folder to Folder Map OCC::Folder(0x812677c00)
03-17 00:00:25:946 101358 OCC::FolderWatcherPrivate::slotAddFolderRecursive: (+) Watcher: "/usr/home/itorres/ownCloud
@itorres
itorres / 20160316-OCC-host-not-found-error
Created March 16, 2016 23:28
OCC FreeBSD errors for folders with > 50000 files Raw
magellan:~$ owncloud --logfile -
03-17 00:04:41:709 101382 OCC::Application::setupLogging: "################## ownCloud ca_ES () 2.1.1"
03-17 00:04:41:709 101382 OCC::Application::setupTranslations: void OCC::Application::setupTranslations() Using "ca_ES" translation
03-17 00:04:41:711 101382 unknown: QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-itorres'
03-17 00:04:41:712 101382 OCC::SocketApi::SocketApi: SocketApi: server started, listening at "/tmp/runtime-itorres/ownCloud/socket"
03-17 00:04:41:712 101382 OCC::FolderMan::FolderMan: setting remote poll timer interval to 30000 msec
03-17 00:04:41:841 101382 OCC::FolderMan::setupFolders: * Setup folders from settings file
03-17 00:04:41:841 101382 OCC::Folder::checkLocalPath: Checked local path ok
03-17 00:04:41:842 101382 OCC::FolderMan::addFolderInternal: Adding folder to Folder Map OCC::Folder(0x812677c00)
@itorres
itorres / rename-shell.el
Created July 13, 2016 14:33
Emacs function to rename shell buffer based on path and tramp host (if this is a tramp buffer)
(defun my-rename-shell-buffer ()
"Rename the current shell buffer name."
(interactive)
(let ((candidate-name
(concat
(if (string-prefix-p "/ssh:" default-directory)
(concat tramp-current-host ":")
"")
(file-name-base (directory-file-name default-directory)))))
(rename-buffer (format "*shell* <%s>" candidate-name))))