Skip to content

Instantly share code, notes, and snippets.

View sir4ju1's full-sized avatar

Sirajul sir4ju1

  • lolobyte
View GitHub Profile
@sir4ju1
sir4ju1 / FindClosesLocation.cs
Created April 25, 2014 09:52
Find Closest Location from longitude and latitude within Sql database using Linq
var constValue = 57.2957795130823D
var constValue2 = 3958.75586574D;
var searchWithin = 20;
double latitude = ConversionHelper.SafeConvertToDoubleCultureInd(Latitude, 0),
longitude = ConversionHelper.SafeConvertToDoubleCultureInd(Longitude, 0);
var loc = (from l in DB.locations
let temp = Math.Sin(Convert.ToDouble(l.Latitude) / constValue)
@sir4ju1
sir4ju1 / calculateAge.cs
Created April 25, 2014 09:47
Calculate someone's age in C#
public int CalculateAge(Datatime bday)
{
DateTime today = DateTime.Today;
int age = today.Year - bday.Year;
if (bday > today.AddYears(-age)) age--;
return age;
}
@sir4ju1
sir4ju1 / sendMail.cs
Created April 25, 2014 01:33
Send EMail using Gmail from ASP Web application
protected void SendMail()
{
MailMessage msg = new MailMessage();
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
try
{
msg.Subject = "Add Subject";
msg.Body = "Add Email Body Part";
msg.From = new MailAddress("Valid Email Address");
msg.To.Add("Valid Email Address");
@sir4ju1
sir4ju1 / getLocationName.js
Last active August 29, 2015 13:59
get location name using reverse geocoding by lattitude and longitude
var latlng = '40.714224,-73.961452';
var url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='+latlng+'&sensor=false';
$.get(url, function(result, response) {
if(result.status === 'OK' && result.results.length > 0) {
var res = result.results[0];
console.log(res.formatted_address);
}
});
@sir4ju1
sir4ju1 / group_concat.sql
Created April 16, 2014 01:24
group_concat equivalent
SELECT
G.GROUP_ID,
G.GROUP_NAME,
stuff(
(
select cast(',' as varchar(max)) + U.USERNAME
from USER_GROUPS U
WHERE U.GROUP_ID = G.GROUP_ID
order by U.USERNAME
for xml path('')
/**
Usage: Just include this script after Marionette and Handlebars loading
IF you use require.js add script to shim and describe it in the requirements
*/
(function(Handlebars, Marionette) {
Marionette.Handlebars = {
path: 'templates/',
extension: '.handlebars'
};
@sir4ju1
sir4ju1 / base64.js
Created March 28, 2014 09:53
encode and decode string to base64 [Javascript]
/**
*
* Base64 encode / decode
*
**/
var Base64 = {
// private property
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
@sir4ju1
sir4ju1 / readcsv.cs
Last active June 8, 2016 07:11
Read CSV of collection of DSE Data and write to SQLite using ORMLITE
String path = HttpContext.Current.Server.MapPath(@"~\App_Data\all_files\");
var d = new DirectoryInfo(path); //Assuming Test is your Folder
FileInfo[] Files = d.GetFiles("*.csv"); //Getting Text files
var sb = new StringBuilder();
var dbFactory = new OrmLiteConnectionFactory(SqliteFileDb, false, SqliteDialect.Provider);
using (IDbConnection db = dbFactory.Open())
{
db.CreateTableIfNotExists<ModelQuote>();
List<ModelQuote> quotes = new List<ModelQuote>();
foreach (FileInfo file in Files)
@sir4ju1
sir4ju1 / androidDisplayScreen.java
Last active December 29, 2015 03:39
Android device width in pixel
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
@sir4ju1
sir4ju1 / facebookLikeAndroid.java
Last active December 28, 2015 21:29
Facebook Like button for android
public static Intent getOpenFacebookIntent(Context context) {
try {
context.getPackageManager()
.getPackageInfo("com.facebook.katana", 0); //Checks if FB is even installed.
return new Intent(Intent.ACTION_VIEW,
Uri.parse("fb://profile/254175194653125")); //Trys to make intent with FB's URI
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.facebook.com/sentiapps")); //catches and opens a url to the desired page