Posts

Showing posts with the label filter

How to get the list of lambda functions filtered by runtime (or any other attrib) using aws-cli

Pretty easy. For example, if I want to get the list of lambda functions that use the nodejs8.10 runtime, I can do something like: aws lambda list-functions --query 'Functions[?Runtime==`nodejs8.10`].[FunctionName]' --output text | tr '\r\n' ' '

Simple real time search and filter using jQuery

Let's say you have a list of HTML elements (div) and you want to implement the search and filter functionality. Here is dead simple example: Assuming your HTML block looks like the following: <div> <input type="text" id="search" placeholder="Type to search"> <button id="search-btn">Search</button> </div> <div class="list-partner"> <div class="partner-item">...</div>         <div class="partner-item">...</div>         <div class="partner-item">...</div> </div> And this javascript snippet will add the magic: <script> var rows = jQuery('.list-partner .partner-item'); jQuery('#search-btn').click(function() { var val = jQuery.trim(jQuery('#search').val()).replace(/ +/g, ' ').toLowerCase(); rows.each(function(){ var itemtxt = jQuery(this).text().replace(/\s+/...

Arrange posts by "order" attribute in WordPress

It's just simple as this function: function my_get_posts( $query ) {     if ( is_home() && false == $query->query_vars['suppress_filters'] )                 $query->set('orderby', 'menu_order');                 $query->set('order', 'ASC');      return $query; } Basically, you need to order the posts by menu_order attribute.

Search and Filter items in grid layout with isotop javascript library

I want to create a portfolio page that listing all of my projects with search and filter functionalities. I search through a lot of javascript libraries and isotope is the only one that I can make it to work (I tried Filterizr , it worked, but if the number of items is about 100, everything will be broken): Isotope official page: http://isotope.metafizzy.co/ This is a working example. It's easy, just read through the code and you will understand: Isotope - filtering with search field and button filters show all metal transition alkali and alkaline-earth not transition metal but not transition Mercury Hg 80 200.59 Tellurium Te 52 127.6 Bismuth Bi 83 208.980 Lead Pb 82 207.2 Gold Au 79 196.967 Potassium K 19 39.0983 Sodium Na 11 22.99 Cadmium Cd 48 112.411 Calcium Ca 20 40.078 Rhenium Re 75 186.207 Thallium Tl 81 204.383 Antimony Sb 51 121.76 Cobalt Co 27 58.933 Ytterbium Yb 70 173.054 Argon Ar 18 39.948 Nitrogen N 7 14.007 Uranium U 92 238.029 Plutonium Pu 94 (244) ...

Get all MS Active Directory group members's email addresses using python

Using python-ldap you can get pretty much out of your MS Active Directory. For example, the following snippet can help you get all the members of a AD group: Usage: $ python ad_utils.py "your group name"

Query only enabled users in MS Active Directory

You can use this filter to query only enabled users in MS Active Direcotory: (&(objectCategory=person)(objectClass=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))

Filter email addresses with egrep

You can use the following command to filter email addresses from text: egrep -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b" For example, to get email addresses of all users with wp-cli: $ wp user list | egrep -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b" Cool huh?!

Google Apps Script - Send SMS when receiving an email in GMail

Image
So, you don't have Internet access but still want to be notified whenever someone special email you (GMail)? Here you go: Google Apps Script FTW. 1. In GMail, create a label name "Send SMS", then create a filter to apply that label to whichever messages you want. For example, every message coming from the email address my-love-one@gmail.com will be applied the "Send SMS" label. 2. Go to Google Apps Script , create a blank project, paste this script into the script editor: Every time the Gms_send_sms runs, it will get all email messages which have "Send SMS" label. Create an event in the Google Calendar for each message. Create an SMS notification for each of those events. Remove the label of those messages 3. In the script editor, select Resources menu >> Current project's triggers >> create a trigger to run the Gms_send_sms function every 5 minutes. You will need to grant permissions for the script to access your gmail...

How to output raw html text with Django template

By default, Django escapes or quotes all the text outputs in the template because of the security matter. It means that if Django template will render any html tag as text, not as html tag. But, if you want, you can display those html outputs as html tags using the Django built-in template tags: safe For example, I will return this object to the template with: myobject.mytextfield = '<strong>This is my text</strong>' + Without safe filter: {{ myobject.mytextfield  }} will be rendered as: "<strong>This is my text</strong>" + With safe filter: {{ myvar.mytextfield |safe }} will be rendered as: " This is my text " Reference:   https://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe

Linux - List files filtered by owner and permissions

This is quite an interesting and common question in linux: List all the files in a folder that are owned by a the user "trinh", with permissions "-rw-r--r-- " 1. The easiest way is to use ls command and chain filter with grep : ls -lt . | grep trinh | grep '\-rw\-r\-\-r\-\-' 2. But, if you don't want to escape these permission characters, you can use awk to translate them into number. So, we will translate " -rw-r--r-- " as following: + "-" : the first character indicates whether it is a file or a directory + "rw-" : the next 3 characters is the owner's right, can be translated to 110 which means 6 in decimal system. + "r--": next 3 characters is the group's right, is 100 in binary and 4 in decimal. + "r--": the last 3 characters is the other users's right, 100 in binary, and 4 in decimal. So, "-rw-r--r--" is 644 in decimal system. ls -lt . | grep trinh | aw...

php5-ldap - Useful ldap snipet

This is a super useful php snipet to debug the ldap search: #============================================================================== # Configuration #============================================================================== # LDAP $ldap_url = "ldaps://ldap.server1 ldaps://ldap.server2"; $ldap_binddn = "cn=manager,dc=example,dc=com"; $ldap_bindpw = "P@ssw0rd"; $ldap_base = " dc=example,dc=com "; #$ldap_filter = "(&(objectClass=person)(uid={login}))"; $ldap_filter = "(&(objectClass=user)(sAMAccountName={login})(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"; $login = "genius"; # Connect to LDAP $ldap = ldap_connect($ldap_url); ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); # Bind if ( isset($ldap_binddn) && isset($ldap_bindpw) ) { $bind = ldap_bind($ldap, $ldap_binddn, $ldap_bindpw); } else { $bind = ldap_b...

LDAP - Filter syntax example

Example: ldap_filter = "(&(objectClass=user)(|(sn=*{lastname}*)(givenName=*{firstname}*))(!(userAccountControl:1.2.840.113556.1.4.803:=2)))" & => AND |  => OR !  => NOT References: http://www.zytrax.com/books/ldap/apa/search.html

Django - Get a list of users of a certain group

To get a list of users of a certain group (let's call it 'MyGroup'): from django.contrib.auth import User, Group users = User.objects.filter(groups=Group.objects.get(name='MyGroup')) or: users = User.objects.filter(groups__name__in=['MyGroup'])