Skip to content

Instantly share code, notes, and snippets.

View rajkumar-p's full-sized avatar

Rajkumar rajkumar-p

View GitHub Profile
@rajkumar-p
rajkumar-p / create_exclusive_file.cpp
Last active August 12, 2019 13:11
Create exclusive file
void create_exclusive_file(char *filename)
{
int fd = open(filename, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
if (fd == -1) {
printf("Error creating file: %s\n", filename);
printf("Error: %s\n", strerror(errno));
return;
} else {
printf("Created exclusive file: %s\n", filename);
}
@rajkumar-p
rajkumar-p / create_exclusive_file_wrong.cpp
Last active August 12, 2019 13:04
Create an exclusive file
void create_exclusive_file(char *filename)
{
int fd = open(filename, O_RDWR);
if (fd == -1) {
// Check other errors here
// We shall assume that we failed
// due to the file not being there.
// Creating file here
int fd = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd == -1) {
void append_to_file(char *filename, char *line, size_t len)
{
off_t off;
int written, closed;
int fd = open(filename, O_RDWR | O_APPEND);
if (fd == -1) {
printf("Error opening file: %s\n", filename);
printf("Error: %s\n", strerror(errno));
return;
}
@rajkumar-p
rajkumar-p / append_to_file_wrong.cpp
Last active August 12, 2019 13:08
Append to file method
void append_to_file(char *filename, char *line, size_t len)
{
off_t off;
int written, closed;
int fd = open(filename, O_RDWR);
if (fd == -1) {
printf("Error opening file: %s\n", filename);
printf("Error: %s\n", strerror(errno));
return;
}
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
bottomMenuButtonConstraintV[1].constant -= 180.0
UIView.animateWithDuration(0.2, delay: 0.0, options: .CurveEaseInOut, animations: {
self.bottomMenuButton.layoutIfNeeded()
}, completion: nil)
}
func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if (!decelerate) {
pushupPopupMenuToOriginalPlace()
func bottomMenuButtonPressed(paramSender: AnyObject) {
if (bottomMenuExpanded) {
for index in 0...3 {
popupMenuButtonsCenterConstraints[index]["x"]?.constant = 0
popupMenuButtonsCenterConstraints[index]["y"]?.constant = 0
}
UIView.animateWithDuration(0.4, delay: 0.0, options: .CurveEaseInOut, animations: {
self.mainScrollView.alpha = 1.0
self.mainScrollView.userInteractionEnabled = true
popupMenuButtonsColors = [
makeUIColor(red: 238.0, green: 53.0, blue: 64.0),
makeUIColor(red: 89.0, green: 52.0, blue: 140.0),
makeUIColor(red: 60.0, green: 182.0, blue: 100.0),
makeUIColor(red: 243.0, green: 137.0, blue: 52.0)
]
for index in 1...4 {
popupMenuButtonsImages.append(UIImage(named: "Popup\(index)")!.imageWithRenderingMode(.AlwaysTemplate))
}
mainViewInsideScrollView = UIView(frame: mainScrollView.bounds)
mainViewInsideScrollView.backgroundColor = UIColor.whiteColor()
mainScrollView.addSubview(mainViewInsideScrollView)
let firstView = UIView()
firstView.translatesAutoresizingMaskIntoConstraints = false
firstView.backgroundColor = makeUIColor(red: 246.0, green: 36.0, blue: 89.0)
let logoImageViewHorizontalCenterConstraint = NSLayoutConstraint(item: logoImageView,
attribute: .CenterX, relatedBy: .Equal, toItem: self.view,
attribute: .CenterX, multiplier: 1.0, constant: 0.0)
self.view.addConstraint(logoImageViewHorizontalCenterConstraint)
override func prefersStatusBarHidden() -> Bool {
return true
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}