Skip to content

Instantly share code, notes, and snippets.

@simplytunde
simplytunde / filesystemprogrammingguide.md
Last active August 29, 2015 14:12
File System Program Guide
    func nsurlForApplicationDirectory()->NSURL?{
         let manager=NSFileManager.defaultManager()
         let possibleURLs=manager.URLsForDirectory(NSSearchPathDirectory.AllLibrariesDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask) //look for the location of app support dir in user dormain
        if let directoryURL=possibleURLs.first as? NSURL{ //pick the first one
           directoryURL.URLByAppendingPathComponent(NSBundle.mainBundle().bundleIdentifier!) //This is this app application support directory
            return directoryURL
        }
        return nil
    }
@simplytunde
simplytunde / swift_syntax.md
Last active August 29, 2015 14:12
Swift:Syntax

#Swift Syntax

Custom Operator

import Foundation

//custom operator
infix operator *** { associativity left }
class Animal:NSObject{
    var  name:String!
    var age:UInt!
@simplytunde
simplytunde / cpp_types.md
Last active August 29, 2015 14:12
C++: Basic Types Gotchas

Basic Types Gotcha

  • If you assign out of range value to signed type, the result is undefined
  • The code below will never terminate because --0 for unsigned int wraps around to become positive
for (unsigned u = 10; u >= 0; --u)
    std::cout << u << std::endl;
  • If combine unsigned and signed in a expression,everything get converted to unsigned. For example,
 unsigned int a=1;
@simplytunde
simplytunde / java_class_gotchas.md
Last active August 29, 2015 14:12
Java:Class Key Notes

Java class key notes

  • Non static block called for every object created
public class HelloWorld{
      public String a;
      public String b;   
      {
         a="A";
         b="B";
 System.out.println("non-static block is called for every object created");
@simplytunde
simplytunde / swift_key_notes.md
Last active August 29, 2015 14:12
Swift: Key Notes
  • You can only use public swift classes or those marked with @objc in objective file.
  • The public properties & method will be available to you
  • The internal properties & method will only be available if objective--c bridging file is present.
  • only private marked with @objc,@IBAction or @IBOutlet will be accessible
  • If you mark a class public(unlike private and internal), it members will have a default access of internal.
  • Tuple type assume access of its most restrictive type.
  • Function assume access of its most restrictive parameter type or return type.
  • access type of associate type in an enum must be at least that of the whole enum. The example below is an error because associated type has overall access of private while the enum has default internal access. Since private is less than internal, its an error. The associated type must either be public or internal
enum ENUMERATION{
@simplytunde
simplytunde / iosfilecoordinator.md
Last active August 29, 2015 14:12
File Coordinator & Presenter

File Coordinator & Presenter

class FileManager:NSObject,NSFilePresenter { //You need to inherit for NSObject
    var fileUrl:NSURL?
    let operationQueue=NSOperationQueue()
    var contentToWrite=String() //This holds content
    var deleted=false //indicate if the file has been deleted
    var presentedItemURL: NSURL? {
        return fileUrl

Metaclass

def setGreeting(self,greeting):
	self.greeting=greeting
	
	
class HelloMetaClass(type):
    def __new__(cls,class_name,base_classes,class_attributes):
	print "Class %s is being created in memory" % (class_name,)
        if  "greetAttribute" not in class_attributes.keys():
@simplytunde
simplytunde / selenium-multiselect.java
Created May 30, 2015 02:45
Selenium: Multiselect
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import java.util.concurrent.TimeUnit;
@simplytunde
simplytunde / selenium-fileupload.java
Created May 30, 2015 04:58
Selenium: File Upload
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class TestClass {
@simplytunde
simplytunde / lifecycle.md
Last active July 27, 2016 19:50
AWS S3 Lifecycle Configuration
{
  "Rules":[
    {
      "ID":"Moving my special dir",
      "Prefix":"dir/",
      "Status":"Enabled",
      "Transitions":[
        {
 "Days":90,