Skip to content

Instantly share code, notes, and snippets.

@jylock
jylock / react-proj-bootstrap-temp.txt
Last active November 15, 2017 11:05
Starting new React project
link to codeacademy tutorial
https://www.codecademy.com/articles/react-setup-v
npm init
npm install --save react
npm install --save react-dom (npm i -S {react,react-dom})
npm install --save-dev babel-core babel-loader babel-preset-env babel-preset-react (npm i -D babel-{core,loader} babel-preset-env babel-preset-react)
In root dir, create a file '.babelrc'
{"presets": ["env", "react"]}
Sorting:
No comparison sort can have better worst-case performance than O(nlog(n))
You can make any sorting algorithm stable by assigning a sequence number to each element and using the sequence number as the
tie-breaker in the multikey sort
Selection Sort:
O(n^2) in all cases. It requires only O(n) swaps, however, it is suitable for data sets where copying is very expensive.
Insertion Sort:
Efficient when dealing with mostly sorted data sets, where it can have O(n) performance, but average and worst cases are O(n^2).
@jylock
jylock / UIViewBordersExtension.swift
Created July 22, 2016 02:23
IBInspectable Setup
import UIKit
extension UIView
{
@IBInspectable var cornerRadius: CGFloat {
get {
return self.layer.cornerRadius
}
set {
self.layer.cornerRadius = newValue
import Foundation
class NetworkService
{
lazy var configuration: NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
lazy var session: NSURLSession = NSURLSession(configuration: self.configuration)
let url: NSURL
init(url: NSURL) {
//comment and uncomment multiple lines
//commenting lines from 66 to 70 (inclusive).
:66,70s/^/#
:66,70s/^#/
# Arithmatic Expansion
# Arithmetic expansion with backticks (often used in conjunction with expr)
# Arithmetic expansion with double parentheses, and using let
z=$(($z+3))
z=$((z+3)) # Also correct.
# Within double parentheses,
#+ parameter dereferencing
#+ is optional.
#include <stdio.h>
#include <stdlib.h>
char* ReadFile(char *filename)
{
char *buffer = NULL;
int string_size,read_size;
FILE *handler = fopen(filename,"r");
if (handler)
//The name of our remote is origin and the default local branch name is master.
//The -u tells Git to remember the parameters, so that next time we can simply
//run git push and Git will know what to do. Go ahead and push it!
git push -u origin master
//diff of most recent commit, which we can refer to using the HEAD pointer
git diff HEAD
git diff --staged
//unstage files by using the git reset command
monitor DP {
status state[5];
condition self[5];
// Pickup chopsticks
Pickup(int i){
state[i] = hungary; // indicate that I'm hungary
test(i); //set state to eating in test() only if my
//left and right neighbors are not eating
if(state[i] != eating)
All POSIX semaphore functions and types are prototyped or defined in semaphore.h. To define a semaphore object, use
sem_t sem_name;
To initialize a semaphore, use sem_init():
int sem_init(sem_t *sem, int pshared, unsigned int value);
sem points to a semaphore object to initialize
pshared is a flag indicating whether or not the semaphore should be shared with fork()ed processes. LinuxThreads does not currently support shared semaphores
value is an initial value to set the semaphore to
Example of use:
sem_init(&sem_name, 0, 10);