Skip to content

Instantly share code, notes, and snippets.

@nl5887
nl5887 / gist:7369357
Created November 8, 2013 10:47
Try to restore all btrfs there is
export DISK=/dev/loop3
export DEST=/data/recov
btrfs-find-root /dev/loop3 2>&1|grep seems|awk '{print $3}' > blocks
for i in $(cat blocks); do mkdir -p $DEST/$i; btrfs restore -o -v -t $line $DISK $DEST/$i; done;
@nl5887
nl5887 / ng_initial.js
Last active December 30, 2015 09:39
app.directive 'ngInitial', ->
restrict: 'A'
controller: ['$scope', '$element', '$attrs', '$parse', ($scope, $element, $attrs, $parse) ->
val = $attrs.sbInitial || $element.val()
getter = $parse($attrs.ngModel)
setter = getter.assign
setter($scope, val)
]
// based on http://jsfiddle.net/7eTMV/20/
// https://github.com/angular-ui/ui-sortable
// https://github.com/johnny/jquery-sortable
angular.module('ui.directives').directive('uiSortable', [
'ui.config', function(uiConfig) {
var options;
options = {};
if (uiConfig.sortable != null) {
angular.extend(options, uiConfig.sortable);
@nl5887
nl5887 / gist:8179591
Created December 30, 2013 09:00
AngularJS websocket factory
app.factory('socket', function ($rootScope) {
var socket = new WebSocket("ws://localhost:8000/data");
return {
onopen: function (callback) {
socket.onopen = function () {
$rootScope.$apply(function () {
callback.apply(socket);
});
};
},
@nl5887
nl5887 / gist:8219016
Created January 2, 2014 13:16
Go Google Appengine RunInBackground
package harvest
import (
_ "encoding/base64"
_ "fmt"
"net/http"
"appengine"
"appengine/runtime"
_ "math"
)
@nl5887
nl5887 / gist:8433808
Created January 15, 2014 10:10
Google App Engine boilerplate: Running background services.
package service
import (
_ "encoding/base64"
_ "fmt"
_ "net/http"
"appengine"
"appengine/urlfetch"
"appengine/runtime"
"time"
@nl5887
nl5887 / gist:8665492
Last active January 4, 2016 19:09
Joins ElasticSearch commit into pyramid transaction manager
import transaction
class ElasticSearchIndexManager(object):
def __init__(self, callable, args, kwargs):
self.callable = callable
self.args = args
self.kwargs = kwargs
# Use the default thread transaction manager.
self.transaction_manager = transaction.manager
@nl5887
nl5887 / gist:9929911
Created April 2, 2014 08:06
LogglyHandler
import logging
import traceback
LOGGLY_URL = "https://logs-01.loggly.com/inputs/{{ LOGGLY_ID }}/tag/{{ TAG }}/"
class LogglyHandler(logging.Handler):
def emit(self, record):
trace = None
exc = record.__dict__['exc_info']
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
import json
import logging
from pyramid.response import Response
from pyramid.view import view_config, view_defaults
from sqlalchemy.sql.expression import and_, or_, not_
from sqlalchemy.orm.exc import NoResultFound
from .models import (