Skip to content

Instantly share code, notes, and snippets.

View cdn34's full-sized avatar

Carlos Nogueira cdn34

  • Anadia, Portugal
View GitHub Profile
@cdn34
cdn34 / pubsub.js
Created December 1, 2017 22:05 — forked from learncodeacademy/pubsub.js
Basic Javascript PubSub Pattern
//events - a super-basic Javascript (publish subscribe) pattern
var events = {
events: {},
on: function (eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},
off: function(eventName, fn) {
if (this.events[eventName]) {
- (void) URLRequestObjCParaOCDN {
//descomenta isto ---> //__weak "nomeDaClasseOndeTensIsto" *weakSelf = self; //nao uses self. em lado nenhum no block, usa weakSelf. nao pode originar leaks e é igual #proTip
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"o teu link aqui"]];
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
//Ele so executa isto quando o request e finalizado, isto e executado numa background thread. Se aqui dentro precisares de usar um "self." diz-me que ensino-te a fazer um weakify ao self para nao teres um memory leak. O "error" so traz erros quando nao tens net e assim, o data é onde vem o json ou o erro do body, o response e onde veem os headers.
@cdn34
cdn34 / gist:20bdb789e5d47446dcdb74c1cbde691b
Created April 13, 2018 13:01 — forked from kgn/gist:5986379
A UIImage category class method for drawing icon font ligatures to images
+ (UIImage *)iconWithFont:(UIFont *)font named:(NSString *)iconNamed forSize:(CGFloat)fontSize{
static NSCache *cache = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
cache = [[NSCache alloc] init];
});
NSString *identifier = [NSString stringWithFormat:@"%@%@%f", font.fontName, iconNamed, fontSize];
UIImage *image = [cache objectForKey:identifier];
if(image == nil){
@cdn34
cdn34 / node-modules-in-react-native.md
Created July 17, 2018 10:26 — forked from parshap/node-modules-in-react-native.md
Running Node Modules in React Native

Running Node Modules in React Native

How to use packages that depend on Node.js core modules in React Native.

Node.js Core Modules

Node has several modules that are automatically available via require(): http, crypto, etc. While these modules are available in Node, they are not automatically available in other environments

@cdn34
cdn34 / README.md
Created July 19, 2018 14:23 — forked from hofmannsven/README.md
My simply Git Cheatsheet
import numpy as np
class NeuralNetwork(object):
#def sigmoid(x):
#return 1 / (1 + np.exp(-x))
def __init__(self, input_nodes, hidden_nodes, output_nodes, learning_rate):
# Set number of nodes in input, hidden and output layers.
@cdn34
cdn34 / React Native Clear Cache
Created May 11, 2020 12:43 — forked from jarretmoses/React Native Clear Cache
Clearing the Cache of your React Native Project
RN < 0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
RN >= 0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
npm >= 5 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache verify && npm install && npm start -- --reset-cache
Windows - del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & npm install & npm start -- --reset-cache
@cdn34
cdn34 / multiple-ssh-authkeys.md
Created March 5, 2021 22:04 — forked from otkrsk/multiple-ssh-authkeys.md
Add multiple SSH keys to the authorized_keys file to enable SSH authentication when connecting to a server.

Step 1: Generate first ssh key Type the following command to generate your first public and private key on a local workstation. Next provide the required input or accept the defaults. Please do not change the filename and directory location.

workstation 1 $ ssh-keygen -t rsa

Finally, copy your public key to your remote server using scp