Skip to content

Instantly share code, notes, and snippets.

Nordin-010 Nordin-010

  • Netherlands, Rotterdam
Block or report user

Report or block Nordin-010

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Nordin-010
Nordin-010 / nsnotification.m
Last active Sep 30, 2019
NSNotification example
View nsnotification.m
- (void) subscribeNotificationWithName: (NSString*) name {
[ [NSNotificationCenter defaultCenter ] addObserver: self
selector: @selector(didReceiveNotification:)
name: name
object: nil ];
}
- (void) didReceiveNotification: (NSNotification *) notification {
NSLog(@"didReceiveNotification");
@Nordin-010
Nordin-010 / ifelse.swift
Last active Apr 9, 2019
How to improve this snippet of Swift code. I have like more than 10 checkboxes
View ifelse.swift
var socialData: SocialData? = storage.data("social")
...
...
// checkLiveAudio = NSButton (CheckBox button)
...
if let data = socialData {
if data.isAudioEnabled() {
checkLiveAudio.state = NSControl.StateValue.on
} else {
checkLiveAudio.state = NSControl.StateValue.off
View optionals.swift
// variables declaration
var str = "Hello, playground"
var x = Int(10)
// class definition
class ParentClass {
func writeText(_ text: String?) -> Void {
print("\(text ?? "empty text")")
}
}
View route-with-timelogger.js
var express = require('express')
var router = express.Router()
// middleware that is specific to this router
// this will be called for every request (get, put, update and delete)
router.use(function timeLog (req, res, next) {
console.log('Time: ', Date.now())
next() // pass control to the nex router int he chain
})
// define the home page route
View route-with-multiple-handlers.js
var cb0 = function (req, res, next) {
console.log('CB0')
next() // don't forget to call next()!
}
var cb1 = function (req, res, next) {
console.log('CB1')
next() // don't forget to call next()!
}
View route-with-2-handlers.js
// route handler with 2 handlers
route.get('/example/b', function (req, res, next) { // handler 1
console.log('the response will be sent by the next function ...')
next() // don't forget to call next() for passing control to the nex callback
}, function (req, res) { // handler 2
res.send('Hello from B!')
})
View async-await2.js
/**
* This function returns a promise to fetch a user by id
*/
function getUserWithId(id) {
return new Promise((resolve, reject) => {
// Look for a user with id in the database
User.find({_id: id}, (user, err) => {
if(err) return reject(err);
// on success
View async-await.js
/**
* promise object
*/
function getUserWithId(id) {
return new Promise((resolve, reject) => {
// Look for a user with id in the database
User.find({_id: id}, (user, err) => {
if(err) return reject(err);
@Nordin-010
Nordin-010 / promise_example2.js
Created Jan 15, 2019
Here we're chaining multiple promises, which solves the callback hell.
View promise_example2.js
/**
* This function returns a promise to fetch a user by id
*/
function getUserWithId(id) {
return new Promise((resolve, reject) => {
// Look for a user with id in the database
User.find({_id: id}, (user, err) => {
if(err) return reject(err);
// on success
View promise_example1.js
/**
* promise object
*/
function getUserWithId(id) {
return new Promise((resolve, reject) => {
// Look for a user with id in the database
User.find({_id: id}, (user, err) => {
if(err) return reject(err);
You can’t perform that action at this time.