Skip to content

Instantly share code, notes, and snippets.

@gprasant
gprasant / filter.m
Last active September 19, 2016 23:00
Avoiding Stringly Typed Programming - Filtering
NSMutableArray *people = @[person1, person2, person3];
// Option 1:Filtering with Strings
NSPredicate *gt_1M = [NSPredicate predicateWithFormat:@"heightInMeters > 1.0"];
NSArray *tallFolks = [people filteredArrayUsingPredicate:gt_1M];
for (BNRPerson *p in tallFolks) {
NSLog(@"<Height: %f>", p.heightInMeters);
}
@gprasant
gprasant / java_proj_setup.md
Created June 9, 2015 23:58
Steps to create a Java project

Setting up a new java project

  1. Make a new directory for the project

  2. Add a pom.file with the contents (Update it to your project name and dependencies as required)

     <?xml version="1.0" encoding="UTF-8"?>
     <project xmlns="http://maven.apache.org/POM/4.0.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

@gprasant
gprasant / tmux_keybindings.md
Last active October 16, 2015 18:20
tmux keybindings

Key bingings

Purpose command
detach from session PRE d
go to window by number PRE <0..9>
enter command mode PRE :
list windows PRE w
rename window PRE ,
close current window PRE &
divide window vertically PRE
/Users/pguruprasad/.rvm/gems/ruby-1.9.2-p290-patched@touch-international/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:240:in `require'
/Users/pguruprasad/.rvm/gems/ruby-1.9.2-p290-patched@touch-international/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:240:in `block in require'
/Users/pguruprasad/.rvm/gems/ruby-1.9.2-p290-patched@touch-international/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:223:in `block in load_dependency'
/Users/pguruprasad/.rvm/gems/ruby-1.9.2-p290-patched@touch-international/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:640:in `new_constants_in'
/Users/pguruprasad/.rvm/gems/ruby-1.9.2-p290-patched@touch-international/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:223:in `load_dependency'
/Users/pguruprasad/.rvm/gems/ruby-1.9.2-p290-patched@touch-international/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:240:in `require'
/Users/pguruprasad/Projects/touch-international/lib/tasks/routes_check.rake
public class HomeControllerAsync : AsyncController
{
/// depends on long running service call.
public void FindAnswerAsync()
{
var wc = new WebClient();
wc.DownloadStringCompleted += (s, e) => {
AsyncManager.Parameters["result"] = e.result;
AsyncManager.OutstandingOperations.Decrement();
}
public static bool operator ==(Coordinate c1, Coordinate c2)
{
return c1.Equals(c2);
}
USE {dbname}
GO
EXEC sp_changedbowner 'sa'
ALTER DATABASE {dbname}SET TRUSTWORTHY ON
public ViewResult Save(Model modelToSave)
{
if(ModelState.isValid)
{
modelToSave.Save();
TempData["Message"] = "Saved Successfully";
// redirects to the list action if the save is successful
return RedirectToAction("Index");
}
//if there are any errors, the same edit View is returned.
return RedirectToAction("Index", new {message="Saved successfully"});
public ViewResult Save(Model modelToSave)
{
if(ModelState.isValid)
{
modelToSave.Save();
// redirects to the list action if the save is successful
return RedirectToAction("Index");
}
//if there are any errors, the same edit View is returned.
return View("Edit", modelToSave);