Skip to content

Instantly share code, notes, and snippets.

View dumindu's full-sized avatar
🦄
One step at a time

Dumindu Madunuwan dumindu

🦄
One step at a time
View GitHub Profile
let a = true;
let b = false;
let c = !a; //false
let d = a && b; //false
let e = a || b; //true
let a = 1;
let b = 2;
let c = a & b; //0 (01 && 10 -> 00)
let d = a | b; //3 (01 || 10 -> 11)
let e = a ^ b; //3 (01 != 10 -> 11)
let f = a << b; //4 (add 2 positions to the end -> '01'+'00' -> 100)
let g = a >> a; //0 (remove 2 positions from the end -> o̶1̶ -> 0)
let a = !-2; //1
let b = !-1; //0
let c = !0; //-1
let d = !1; //-2
let mut a = 2;
a += 5; //2 + 5 = 7
a -= 2; //7 - 2 = 5
a *= 5; //5 * 5 = 25
a /= 2; //25 / 2 = 12 not 12.5
a %= 5; //12 % 5 = 2
a &= 2; //10 && 10 -> 10 -> 2
a |= 5; //010 || 101 -> 111 -> 7
let a = 15;
let b = (a as f64) / 2.0; //7.5
$isCron = 'cli' === strtolower(PHP_SAPI);
@dumindu
dumindu / bash
Last active March 17, 2016 00:51
screen -S dumindu
pv /home/usera/download/public/db_dump.sql.gz | gunzip | mysql db_name;
#exit from screen without terminating task
ctrl ad
#to check back
screen -r dumindu
#to terminate
ctrl d
//Creating vectors - 2 ways
let mut a = Vec::new(); //1.with new() keyword
let mut b = vec![]; //2.using the vec! macro
//Creating with data types
let mut a2: Vec<i32> = Vec::new();
let mut b2: Vec<i32> = vec![];
let mut b3 = vec![1i32, 2, 3];//sufixing 1st value with data type
//Creating with data
let mut v = vec![1, 2, 3, 4, 5];
for i in &v {
println!("A reference to {}", i);
}
for i in &mut v {
println!("A mutable reference to {}", i);
}
// Struct Declaration
struct Color {
red: u8,
green: u8,
blue: u8
}
fn main() {
// creating an instance
let black = Color {red: 0, green: 0, blue: 0};