Tutorial by Examples: bi

C-style bit-manipulation A bit can be toggled using the XOR operator (^). // Bit x will be the opposite value of what it is currently number ^= 1LL << x; Using std::bitset std::bitset<4> num(std::string("0100")); num.flip(2); // num is now 0000 num.flip(0); // num is n...
C-style bit-manipulation The value of the bit can be obtained by shifting the number to the right x times and then performing bitwise AND (&) on it: (number >> x) & 1LL; // 1 if the 'x'th bit of 'number' is set, 0 otherwise The right-shift operation may be implemented as either a...
C-style bit-manipulation // Bit n will be set if x is 1 and cleared if x is 0. number ^= (-x ^ number) & (1LL << n); Using std::bitset set(n,val) - sets bit n to the value val. std::bitset<5> num(std::string("00100")); num.set(0,true); // num is now 00101 num.set(...
Basic usage of dependency injection is done by the annotations. When you need to tweak things a little bit, you need custom code to further specify how you want some classes to be instantiated and injected. This code goes in what is called a Module. import com.google.inject.AbstractModule // Pla...
Abilities are defined in the Ability class using can and cannot methods. Consider the following commented example for basic reference: class Ability include CanCan::Ability def initialize(user) # for any visitor or user can :read, Article if user if user.admin? ...
Once the number of abilities definitions start to grow in number, it becomes more and more difficult to handle the Ability file. The first strategy to handle these issue is to move abilities into meaningful methods, as per this example: class Ability include CanCan::Ability def initialize(...
By default, one should subscribe to event using inspector, but sometimes it's better to do it in code. In this example we subscribe to click event of a button in order to handle it. using UnityEngine; using UnityEngine.UI; [RequireComponent(typeof(Button))] public class AutomaticClickHandler :...
This bidirectional mapping requires the mappedBy attribute on the OneToMany association and the inversedBy attribute on the ManyToOne association. A bidirectional relationship has both an owning and inverse side. OneToMany relationships can use join tables, so you have to specify an owning side. Th...
#include <iostream> #include <functional> using std::placeholders::_1; // to be used in std::bind example int stdf_foobar (int x, std::function<int(int)> moo) { return x + moo(x); // std::function moo called } int foo (int x) { return 2+x; } int foo_2 (int x, in...
You can read an a binary file using this piece of code in all recent versions of Java: Java SE 1.4 File file = new File("path_to_the_file"); byte[] data = new byte[(int) file.length()]; DataInputStream stream = new DataInputStream(new FileInputStream(file)); stream.readFully(data); s...
CL-PPCRE:REGISTER-GROUPS-BIND will match a string against a regular expression, and if it matches, bind register groups in the regex to variables. If the string does not match, NIL is returned. (defun parse-date-string (date-string) (cl-ppcre:register-groups-bind (year month day) (...
Say you want to print variables in a 3 character column. Note: doubling { and } escapes them. s = """ pad {{:3}} :{a:3}: truncate {{:.3}} :{e:.3}: combined {{:>3.3}} :{a:>3.3}: {{:3.3}} :{a:3.3}: {{:3.3}} :{c:3...
A branch is just a pointer to a commit, so you can freely move it around. To make it so that the branch is referring to the commit aabbcc, issue the command git reset --hard aabbcc Please note that this will overwrite your branch's current commit, and as so, its entire history. You might loose s...
section .data msg db "Hello world!",10 ; 10 is the ASCII code for a new line (LF) section .text global _start _start: mov rax, 1 mov rdi, 1 mov rsi, msg mov rdx, 13 syscall mov rax, 60 mov rdi, 0 syscall If you want to e...
Strings are immutable. You just cannot change existing string. Any operation on the string crates a new instance of the string having new value. It means that if you need to replace a single character in a very long string, memory will be allocated for a new value. string veryLongString = ... // m...
C-style bit-manipulation x = -1; // -1 == 1111 1111 ... 1111b (See here for an explanation of why this works and is actually the best approach.) Using std::bitset std::bitset<10> x; x.set(); // Sets all bits to '1'
Angular has some magic under its hood. it enables binding DOM to real js variables. Angular uses a loop, named the "digest loop", which is called after any change of a variable - calling callbacks which update the DOM. For example, the ng-model directive attaches a keyup eventListener to...
The method compareTo should be used to compare BigDecimals: BigDecimal a = new BigDecimal(5); a.compareTo(new BigDecimal(0)); // a is greater, returns 1 a.compareTo(new BigDecimal(5)); // a is equal, returns 0 a.compareTo(new BigDecimal(10)); // a is less, returns -1 Commonly you shou...
Binding is the process of assigning an object to an identifier or variable name. Early binding (also known as static binding) is when an object declared in Excel is of a specific object type, such as a Worksheet or Workbook. Late binding occurs when general object associations are made, such as the ...
x = 5 x += 7 for x in iterable: pass Each of the above statements is a binding occurrence - x become bound to the object denoted by 5. If this statement appears inside a function, then x will be function-local by default. See the "Syntax" section for a list of binding statements. ...

Page 9 of 29