This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ldap | |
# Initialize and bind | |
con = ldap.initialize('ldap://10.0.0.23') | |
dn = "cn=test,dc=example,dc=com" | |
pw = "Pass1" | |
con.simple_bind_s(dn, pw) | |
# Run a query against the directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A generic confirmation for risky actions. | |
* Usage: Add attributes: ng-really-message="Are you sure"? ng-really-click="takeAction()" function | |
*/ | |
angular.module('app').directive('ngReallyClick', [function() { | |
return { | |
restrict: 'A', | |
link: function(scope, element, attrs) { | |
element.bind('click', function() { | |
var message = attrs.ngReallyMessage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('filters', []). | |
filter('fromNative', function() { | |
/** | |
* Transform any "foreign key" value to its string representation, | |
* similar to the way ng-options works for a <select> element, | |
* | |
* Example: | |
* Let's say we have an item object with a userID property (item.userID = 5) | |
* This ID translates to a 'username' from a 'users' object, that looks | |
* something like this: users = [ {id: 6, name: 'john'}, ... ]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import iptc | |
# sudo iptables -t filter -F | |
if __name__=="__main__": | |
chain = iptc.Chain(iptc.Table(iptc.Table.FILTER), "INPUT") | |
# Block | ANY | ANY | |
rule_block_all = iptc.Rule() | |
rule_block_all.in_interface = "eth+" | |
rule_block_all.src = "0.0.0.0/0.0.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.contenttypes import generic | |
from django.contrib.contenttypes.models import ContentType | |
class GenericLinkedModel(models.Model): | |
""" | |
Abstract base model that allows for an object to be linked (foreign-keyed) | |
to various models. Useful example: Comments or tags for different types of | |
objects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<style> | |
.wrap{ | |
position: relative; | |
width: 30%; /* Width */ | |
float: left; | |
margin: 5px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $img = ..., | |
imagesLoadedCallback = function() { | |
// Do stuff | |
} | |
(function waitForImageLoaded() { | |
if ($img[0].complete && $img[0].naturalWidth > 0) { | |
imagesLoadedCallback(); | |
} | |
else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pythonToJsFormats = Object.freeze({ | |
'%a': 'ddd', | |
'%A': 'dddd', | |
'%w': 'd', | |
'%d': 'DD', | |
'%b': 'MMM', | |
'%B': 'MMMM', | |
'%m': 'MM', | |
'%y': 'YY', | |
'%Y': 'YYYY', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LazyProperty(object): | |
""" | |
A descriptor protocol implementation used for wrapping a lambda | |
function (without parameters) to behave like property access. | |
Usage, only within a class definition: all_users = LazyProperty(lambda: []) | |
""" | |
@staticmethod | |
def is_lambda(v): | |
lambda_example = lambda: 0 | |
return isinstance(v, type(lambda_example)) and v.__name__ == lambda_example.__name__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="nav site-nav"> | |
<li><a href=#>Lorem</a></li><!-- | |
--><li><a href=#>Ipsum</a></li><!-- | |
--><li class=flyout> | |
<a href=#>Dolor</a> | |
<!-- Flyout --> | |
<ul class="flyout-content nav stacked"> | |
<li><a href=#>Foo Bar</a></li> |