Skip to content

Instantly share code, notes, and snippets.

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

Nitesh Rijal openrijal

🇳🇵
<code />
View GitHub Profile
@openrijal
openrijal / media_to_uri.java
Last active April 21, 2021 03:26
Get Path from URI in Android.
/*
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);
@openrijal
openrijal / rockpaperscissors.js
Last active December 16, 2015 01:08
Rock,Paper, Scissors GAME
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);
@openrijal
openrijal / ip2geo.sh
Created April 3, 2013 18:33
Bash Script to find Geolocation from IP Addresses in apache's access log. You need to have "geoiplookup" package from GeoLite package. The excerpts are taken from http://danielmiessler.com/blog/a-simple-script-for-harvesting-dns-country-state-and-city-information-from-a-list-of-ip-addresses
#!/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