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
#!/usr/bin/env bash | |
cat /var/log/apache2/access_log | awk '{print $1}' > ips.txt | |
uniq ips.txt > uniqips.txt | |
IPS=`cat uniqips.txt` | |
for i in $IPS | |
do | |
echo "$i,`geoiplookup $i | cut -d "," -f2 | sed -e 's/^[\t]//'`" >> ipinfo.csv | |
done |
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 userChoice = prompt("Do you choose rock, paper or scissors?"); | |
var computerChoice = Math.random(); | |
if (computerChoice <= (1/3)) { | |
computerChoice = "rock"; | |
} else if(computerChoice <= (2/3)) { | |
computerChoice = "paper"; | |
} else { | |
computerChoice = "scissors"; | |
} | |
compare(userChoice,computerChoice); |
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
/* | |
Input: URI -- something like content://com.example.app.provider/table2/dataset1 | |
Output: PATH -- something like /sdcard/DCIM/123242-image.jpg | |
*/ | |
public String convertMediaUriToPath(Uri uri) { | |
String [] proj={MediaStore.Images.Media.DATA}; | |
Cursor cursor = getContentResolver().query(uri, proj, null, null, null); | |
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); | |
cursor.moveToFirst(); | |
String path = cursor.getString(column_index); |
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
/* | |
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) { |
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
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; | |
} |
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
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'; |
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
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://' |
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
# 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 [email protected] 'mysqldump -u mydbuser --password=mydbpass mydbname > /destination/path/dump_filename.sql' |
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
# 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>; |
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
''' | |
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]) |
OlderNewer