Posts

Showing posts from October, 2015

ImportError: No module named _io in ubuntu 14.04

After I upgraded my Ubuntu 12.04 server to 14.04, my django app stopped working. I tried to debug it and got this error message:

ImportError: No module named _io

And the reason of this is the python of my virtualenv (2.7.3) and the server's python version (2.7.6) was mismatched. So, what I did to fix the issue was overriding the virtualenv's python binary with the new one:

cp `which python2.7` myenv/bin/python


Ubuntu 14.04 php5-fpm throws unknown instance on service restart

After upgrading my Ubuntu server from 12.04 to 14.04 this morning, I tried to restart php5-fpm and got this error:

Unknown job: php5-fpm

It is a Ubuntu's bug: https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1272788/

One workaround that works for me is:

Create /etc/init/php5-fpm.override file with the single line "reload signal USR2" in it.


Reference:http://stackoverflow.com/questions/19998526/ubuntu-php5-fpm-throws-unknown-instance-on-reload

Getting user's DN from Active Directory by username using python-ldap

To get a user's DN from Active Directory by her username you can use the following python snippet I wrote this morning:



$ python get_dn_by_username.py myusername

Quite useful huh?!

Disabling spam email notification of AntispamBee plugin in WordPress multisite

Antispam Bee is a great spam filtering plugin for WordPress. It's free of charge and ad-free. But the thing is when you apply it for your network, a WordPress multisite with hundred or thousand of blogs, you have to set it up one-by-one. Luckily, I found an easy way to apply the default settings of Antispam Bee for all the blogs, such as disable the spam email notifications or even delete the spam without sending it to the spam folder.

It's quite easy, you just need to open the antispam_bee.php (/path/to/your/wordpress/wp-content/plugins/antispam-bee/) file and modify these lines as following (around line #370, #371):

                                'flag_spam'             => 0,
                                'email_notify'          => 0,


Disabling password complexity rule in Active Directory Windows Server2008

If you want to disable password complexity policy in Active Directory Windows Server 2008, you have to do it using Group Policy:

1. Open Group Policy Management Console (Start > Run > gpmc.msc).

2. Open the Domain, and right-click and Edit the "Default Domain Policy".

3. Go into the "Computer Configuration" > "Windows Settings" > "Security Settings" > "Account Policies", and modify the "Password must meet complexity requirements" setting.

4. Start > Run > gpupdate /force to force update the group policy.

Now you can change the user's password to whatever you want.

Using jQuery to sort table by a pseudo column

In many cases, the web engine that generates data tables (html) is close-sourced and you cannot sort those tables. It is not because the engine does not have a mechanism to sort data. It's just that its behaviors does not satisfy your need. For example, the PowerSchool customization engine.

In PowerSchool, I can output a table of lunch balance information of a student using this template syntax:

~[tlist;gldetail;studentid=~(curstudid);alternatecolor;sortcmd;date,>,time,>;]
  <td>~(date)</td>
  <td>~(time)</td>
  <td>~(neteffect)</td>
  <td>~(runninglunchtotalbalance.students)</td>
  <td colspan="3">~(transdescription)</td>

Did you see the > (greater than) sign? It says that the table will sort by the date and time columns in ascending order. What I want is to make it sort date and time in descending order. So I tried to replace the > with the < (less than) hoping that it would reverse the sorting order.…

Querying Oracle to get students that do not have parent accounts in PowerSchool

You can use this SQL query to get all the students that do not have parent account linked to them in PowerSchool:


SELECT s.LASTFIRST, s.STUDENT_NUMBER, s.FAMILY_IDENT, s.FATHER,                                           u.SSIS_FATHER_EMAIL, s.MOTHER, u.SSIS_MOTHER_EMAIL
FROM students s INNER JOIN u_studentsuserfields u ON s.DCID = u.STUDENTSDCID
WHERE s.DCID not in (SELECT g.STUDENTSDCID FROM guardianstudent g)
       AND s.ENROLL_STATUS = 0;

Displaying Bell Schedule info on admin and teachers pages header of PowerSchool

It's quite useful displaying the bell schedule info of the day on the admin and teachers pages's header in PowerSchool. Here is how to do it:

1. Go to PS Administrator >> Custom Pages

2. Add this following code to wildcards/admin_header_css.txt and wildcards/teacher_header_css.txt

<span id="ssis-date" style="padding-right:20px;">
~[tlist_sql; select b.name as name, listagg(p.ABBREVIATION || ',') WITHIN GROUP ( ORDER BY bi.START_TIME) AS periods
    from ps.calendar_day c inner join ps.BELL_SCHEDULE b on c.BELL_SCHEDULE_ID = b.ID
        inner join ps.BELL_SCHEDULE_ITEMS bi on bi.BELL_SCHEDULE_ID = b.ID
        inner join ps.PERIOD p on p.ID = bi.PERIOD_ID
    where TO_CHAR(c.DATE_VALUE, 'DD-MM-YYYY') = TO_CHAR(CURRENT_DATE, 'DD-MM-YYYY')
        and c.SCHOOLID = ~(curschoolid)
    group by b.name; ]
    <span style="color:#195f7d">~(name):</span> ~(periods)
[/tlist_sql]
</span>

Requirement:  you have to set…

Quote of the day

“When everything is easy one quickly gets stupid.”

― Maxim Gorky.

Using SMTP for emailing in WordPress Multisite

To enable SMTP emailing (use SMTP instead of mail()) in a WordPress Multisite, you can do this:

1. Install this plugin in network admin dashboard:WP MAIL SMTP (https://wordpress.org/plugins/wp-mail-smtp/)

2. Add these settings to wp-config.php:

define('WPMS_ON', true);
define('WPMS_MAIL_FROM', 'myemail@mydomain.com');
define('WPMS_MAIL_FROM_NAME', 'My WordPress Multisite');
define('WPMS_MAILER', 'smtp');// Possible values 'smtp', 'mail', or 'sendmail' 
define('WPMS_SET_RETURN_PATH', 'false');// Sets $phpmailer->Sender if true
define('WPMS_SMTP_HOST', 'smtp.gmail.com'); // The SMTP mail host
define('WPMS_SMTP_PORT', 587); // The SMTP server port number
define('WPMS_SSL', 'tls'); // Possible values '', 'ssl', 'tls' - note TLS is not STARTTLS
define('WPMS_SMTP_AUTH', true); // True turns on SMTP authentication, false turns it off
d…

Mass reset Active Directory users's password remotely using python

In Microsoft Windows Server 2008 (Active Directory Domain Controller), you can reset a user password using command prompt with dsmod:

dsmod user <user dn> -pwd new_password

What if you want to do it from remote? Python and Paramiko module will help:

1. In the Active Directory domain controller, install cygwin with ssh module. Create a ssh user.

2. Still in the Active Directory domain controller, export the user's dn list to a csv file using command prompt:

dsquery user "ou=MyUser,dc=my,dc=domain,dc=com" | dsget user -samid -fn -ln -dn > myusers.csv

3. Open names.csv, add a column name "password" and fill in new password for all the user. Save and copy it to your computer.

4. In your computer (I'm running Ubuntu 14.04), install all the paramiko python module:

$ sudo pip install paramiko

then run this python script:



$ python mass_reset_ad_passwd.py /path/to/myusers.csv

Preparing for PyCon 2016

Image
Alright, I will attend PyCon2016 in Portlan, Oregan:


https://us.pycon.org/2016/
It's time to plan:

Flight ticket: Savings or do some projects.Accomodation:AirBnBVISA: take 1-2 months.
Genius!!!!!!