Skip to content

Instantly share code, notes, and snippets.

View openrijal's full-sized avatar
🇳🇵
<code />

Nitesh Rijal openrijal

🇳🇵
<code />
View GitHub Profile
fastboot -i 0x2A96 devices
fastboot -i 0x2A96 oem unlock
fastboot -i 0x2A96 flash boot boot.img
fastboot -i 0x2A96 flash aboot emmc_appsboot.mbn
fastboot -i 0x2A96 flash modem NON-HLOS.bin
fastboot -i 0x2A96 flash rpm rpm.mbn
fastboot -i 0x2A96 flash sbl1 sbl1.mbn
fastboot -i 0x2A96 flash tz tz.mbn
fastboot -i 0x2A96 flash hyp hyp.mbn
fastboot -i 0x2A96 flash splash splash.img
@openrijal
openrijal / gradleplease.py
Created November 14, 2015 12:29
gradle please commandline utility to copy library name to clipboard
try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
import json, argparse, os, sys, pyperclip
def get(lib):
@openrijal
openrijal / countgoogle.py
Created September 8, 2015 10:35
Python Script to estimate number of results in a google search. Also supports site: and inurl: queries.
#!/usr/bin/python
import sys
from optparse import OptionParser
import json
import urllib
def calculate(searchfor):
query = urllib.urlencode({'q': searchfor})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=2.0&%s' % query
search_response = urllib.urlopen(url)
@openrijal
openrijal / get_prev_next_items_iterable.py
Last active August 29, 2015 14:26
Get Previous and Next items in a forloop in Python
'''
source: http://stackoverflow.com/a/1012089/1777024
'''
from itertools import tee, islice, chain, izip # official documentation https://docs.python.org/2/library/itertools.html
def prev_and_next(my_iterable):
prevs, items, nexts = tee(my_iterable, 3)
prevs = chain([None], prevs)
nexts = chain(islice(nexts, 1, None), [None])
@openrijal
openrijal / pgsql specific
Created July 7, 2015 13:08
Django Related
# to import data from csv to table
\copy <table_name> from '/path/to/csv/filename.csv' DELIMITERS ',' CSV;
# to increase the auto_increment after import
ALTER SEQUENCE tblName_id_seq RESTART WITH <number>;
@openrijal
openrijal / webhost_bkup
Created February 8, 2014 15:22
This bash script is to be run from local machine and it copies remote web files and database to local folder.
# Assumptions
#########################
# remote_host: example.com
# remote_user: johndoe
# db_user: mydbuser
# db_pass: mydbpass
# db_name: mydbname
# to dump mysql database in the remote system from local system
ssh johndoe@example.com 'mysqldump -u mydbuser --password=mydbpass mydbname > /destination/path/dump_filename.sql'
@openrijal
openrijal / gist:8120686
Created December 25, 2013 06:30
BASE_URL for Django from A BASE_URL Template Variable in Django http://www.micahcarrick.com/base-url-in-django.html via @MicahCarrick
context_processors.py
def baseurl(request):
"""
Return a BASE_URL template context for the current request.
"""
if request.is_secure():
scheme = 'https://'
else:
scheme = 'http://'
@openrijal
openrijal / PasswordValidator.java
Created May 1, 2013 12:24
Java Class for verifying minimum password standard.
public class PasswordValidator {
// For character determinations
private static final int CHAR_LOWER_A = 'a';
private static final int CHAR_LOWER_Z = 'z';
private static final int CHAR_UPPER_A = 'A';
private static final int CHAR_UPPER_Z = 'Z';
private static final int CHAR_NUMERIC_ZERO = '0';
private static final int CHAR_NUMERIC_NINE = '9';
@openrijal
openrijal / copy_of_range.java
Created May 1, 2013 12:21
Implementation of Arrays.copyOfRange() in terms of System.arraycopy() for compatibility in older Android versions.
public byte[] copyOfRange(byte[] from, int start, int end){
int length = end - start;
byte[] result = new byte[length];
System.arraycopy(from, start, result, 0, length);
return result;
}
@openrijal
openrijal / string_to_md5.java
Created May 1, 2013 12:17
This method converts any String to MD5 encrypted Strings.
/*
Input: STRING -- something like "myplainpassword"
Output: MD5 STRING -- something like "79054025255fb1a26e4bc422aef54eb4"
*/
public static String convertToMd5(final String inputString) throws UnsupportedEncodingException {
StringBuffer sb = new StringBuffer();
try {
final java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
final byte[] array = md.digest(md5.getBytes("UTF-8"));
for (int i = 0; i < array.length; ++i) {