switch

switch(expression) {
    case n:
        code block
        break;
    case n:
        code block
        break;
    default:
        default code block
}

Tags: 

uiiamge background

UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"statistics"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImageView *imageView = [[UIImageView alloc] initWithImage: image];

[self.view addSubview: imageView];

[self.view sendSubviewToBack: imageView];

Tags: 

uinavigationcontroller

[[self navigationController] popToViewController:obj animated:YES];

[self.navigationController popToRootViewControllerAnimated:YES];

Tags: 

hide status bar

in plist file
set Status bar is initially hidden = YES
add row: View controller-based status bar appearance = NO

[self.navigationController setNavigationBarHidden:YES];

Tags: 

string contains

indexOf returns the position of the string in the other string. If not found, it will return -1:

var s = "foo";
alert(s.indexOf("oo") > -1);

Tags: 

center

Centering lines of text

P { text-align: center }
H2 { text-align: center }

Centering a block of text or an image

P.blocktext {
    margin-left: auto;
    margin-right: auto;
    width: 6em
}
...
<P class="blocktext">This rather...

IMG.displayed {
    display: block;
    margin-left: auto;
    margin-right: auto }
...
<IMG class="displayed" src="..." alt="...">

Centering a block or an image vertically

DIV.container {
    min-height: 10em;
    display: table-cell;
    vertical-align: middle }
...
<DIV class="container">
  <P>This small paragraph...
</DIV>

Tags: 

remove object from array

someArray = [{name:"Kristian", lines:"2,5,10"},
{name:"John", lines:"1,19,26,96"}];
You can use several methods to remove an item from it:

//1
someArray.shift(); // first element removed
//2
someArray = someArray.slice(1); // first element removed
//3
someArray.splice(0,1); // first element removed
//4
someArray.pop(); // last element removed
If you want to remove element at position x, use:

someArray.splice(x,1);

Tags: 

check string is equal

if ( variable.valueOf()=="string" )

"a" == "b"
However, note that string objects will not be equal.

new String("a") == new String("a")
will return false.

Call the valueOf() method to convert it to a primitive for String objects,

new String("a").valueOf() == new String("a").valueOf()

Tags: 

strings

for character in "mouse"{
println(character)
}
m
o
u
s
e

let a 3 , b= 5
// "3 times 5 is 15"
let math result = "\(a) times \(b) is \(a*b)"

Tags: 

for each

var a = ["a", "b", "c"];
a.forEach(function(entry) {
console.log(entry);
});

Tags: 

declaring variables

var mutableDouble = 1.0
mutableDouble = 2.0

let constantDouble = 1.0
// errror constantDouble = 2.0

var optionalDouble:Double ?= nil
optionalDouble = 1.0

if let definiteDouble = optionalDouble {
definiteDouble
}

variable types

Int 1,2,500
Float 0.5
Double
Bool true, false
String "string"
Classname UIView, UIImage

Tags: 

Maze generator

function maze(x,y) {
var n=x*y-1;
if (n<0) {alert("illegal maze dimensions");return;}
var horiz =[]; for (var j= 0; j0 && j0 && (j != here[0]+1 || k != here[1]+1));
}
while (00 && m.verti[j/2-1][Math.floor(k/4)])
line[k]= ' ';
else
line[k]= '-';
else
for (var k=0; k0 && m.horiz[(j-1)/2][k/4-1])
line[k]= ' ';
else
line[k]= '|';
else
line[k]= ' ';
if (0 == j) line[1]= line[2]= line[3]= ' ';
if (m.x*2-1 == j) line[4*m.y]= ' ';
text.push(line.join('')+'\r\n');
}
return text.join('');
}

Tags: 

show column names containing %..%

show column names met naam %rekening%

SELECT table_name, column_name
FROM information_schema.columns
WHERE column_name LIKE '%rekening%'
LIMIT 0 , 30

Tags: 

window size width height

var w = window.innerWidth;
var h = window.innerHeight;

Tags: 

localstorage

local storageif(typeof(Storage)!=="undefined")
{
// Code for localStorage/sessionStorage.
}
else
{
// Sorry! No Web Storage support..
}

random int between

Math.floor((Math.random() * 100) + 1);

Tags: 

set get value from input field

getvar bla = $('#txt_name').val();

set$('#txt_name').val('bla’);

Tags: 

html 5 input minimum length text

<input pattern=".{3,}" required title="3 characters minimum”]]>

Tags: 

click jquery add target

click

html

Click here

js

$( "#target" ).click(function() {

alert( "Handler for .click() called." );

});

Tags: 

on document load jquery

$( document ).ready(function() {

console.log( "ready!" );

});

Tags: 

on mouse down register x y

var clicking = false;

$('.selector').mousedown(function(){
clicking = true;
$('.clickstatus').text('mousedown');
});

$(document).mouseup(function(){
clicking = false;
$('.clickstatus').text('mouseup');
$('.movestatus').text('click released, no more move event');
})

$('.selector').mousemove(function(){
if(clicking == false) return;

// Mouse click + moving logic here
$('.movestatus').text('mouse moving');
});

Tags: 

Pages

Subscribe to hjsnips RSS