Skip to content

Instantly share code, notes, and snippets.

View masnun's full-sized avatar

Abu Ashraf Masnun masnun

View GitHub Profile
from subprocess import Popen, PIPE, call
from sys import argv, exit
from time import sleep
from os import getpid
def get_process_list(app):
ps_aux = Popen(["ps", "aux"], stdout=PIPE)
grep = Popen(["grep", app], stdin=ps_aux.stdout, stdout=PIPE)
awk = Popen(["awk", "{print $2}"], stdin=grep.stdout, stdout=PIPE)
ps_aux.stdout.close()
@masnun
masnun / lein.clj
Last active August 29, 2015 14:11
(require '[clojure.tools.namespace.repl :refer [refresh]])
(refresh)
(-main)
(defproject my-project "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:main my-project.core
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:profiles {:dev {:source-paths ["startup"]}}
:dependencies [[org.clojure/clojure "1.6.0"]
(ns user
(:use [clojure.tools.namespace.repl :only [refresh]]))
(defn rerun
[]
(refresh :after 'my-project.core/-main))
@masnun
masnun / sf.sh
Created August 8, 2012 14:28
Symfony command line tool shortcut
#!/bin/bash
# Expand globs to null when there are no matches
shopt -s nullglob
# Look for either a '<subdir>/console' or a 'symfony' file
until
file=(*/console symfony); [[ -f "$file" ]] && php "$file" "$@" && exit;
do
[[ "$PWD" == "/" ]] && break;
@masnun
masnun / rmpyc.py
Created August 15, 2012 23:17
Remove .pyc files recursively (shell command + django manage.py plugin)
# File: <appname>/management/commands/rmpyc.py
# management and commands directories must be python packages (each must have a __init__.py file)
from django.core.management.base import BaseCommand, CommandError
from subprocess import Popen, STDOUT, PIPE
import shlex, os
class Command(BaseCommand):
def handle(self, *args, **options):
@masnun
masnun / eid.py
Created August 19, 2012 14:09
Pythonic Eid Greeting
#!/usr/bin/env python
class Eid(object):
def __get__(self,instance,owner):
return "Eid-Ul-Fitr "
class Salutation(object):
def __get__(self,instance,owner):
return "Mubarak!"
@masnun
masnun / DefaultController.php
Created August 23, 2012 18:59
Symfony2 entity problem
$entityManager = $this->getDoctrine()->getEntityManager();
$user = new User();
$user->setAddress("Khulna");
$user->setBio("Good guy!");
$user->setEmail("masnun@gmail.com");
$user->setName("Masnun");
$user->setIdentityProvider("facebook");
$user->setProviderId("masnun");
$user->setPhone("8801711960803");
@masnun
masnun / Execution Time
Last active December 15, 2015 17:59
Mapping With Lambda
Lighthouse: ~/Codes/compare
→ time python test.py
python test.py 0.05s user 0.01s system 96% cpu 0.067 total
Lighthouse: ~/Codes/compare
→ time php test.php
php test.php 0.56s user 0.03s system 99% cpu 0.598 total
Lighthouse: ~/Codes/compare
@masnun
masnun / preference.json
Created April 18, 2013 11:08
Sublime Text 2 Preference
{
"auto_indent": true,
"bold_folder_labels": true,
"color_scheme": "Packages/Dayle Rees Color Schemes/LaravelDarker.tmTheme",
"draw_white_space": "all",
"fade_fold_buttons": false,
"fold_buttons": true,
"folder_exclude_patterns":
[
".svn",