This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
We define a magic square to be an `n x n` matrix of distinct positive integers from `1` to `n^2` where the sum of any row, column, or diagonal of length `n` is always equal to the same number: the magic constant. | |
You will be given a `3x3` matrix `s` of integers in the inclusive range `[1,9]`. We can convert any digit to any other digit `b` in the range `[1,9]` at cost of `|a-b|`. Given `s`, convert it into a magic square at minimal cost. Return this minimal cost. | |
Note: The resulting magic square must contain distinct integers in the inclusive range `[1,9]`. | |
Example: $s = [[5, 3, 4], [1, 5, 8], [6, 4, 2]] | |
The matrix looks like this: | |
5 3 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given a string return a number of all possible anagrams | |
func sherlockAndAnagrams(s: String) -> Int { | |
var anagramCount = 0 | |
var frequencyMap = [String: Int]() | |
// Iterate through all possible substrings | |
for i in 0..<s.count { | |
for j in i+1..<s.count + 1 { | |
let substring = String(s[s.index(s.startIndex, offsetBy: i)..<s.index(s.startIndex, offsetBy: j)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given an amount and the denominations of coins available, determine how many ways change can be made for amount. | |
There is a limitless supply of each coin type. | |
Example | |
n = 3 | |
c = [8,3,1,2] | |
There are 3 ways to make change for n=3: {1,1,1}, {1,2}, and {3}. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<h1>subdomain host: {{ this.host }}</h1> | |
</div> | |
</template> | |
<script> | |
export default { | |
async asyncData({ req }) { | |
if (process.server) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
buildModules: [ | |
['@nuxtjs/router', { keepDefaultRouter: true }] | |
], | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Router from 'vue-router' | |
export function createRouter(ssrContext, createDefaultRouter, routerOptions) { | |
const options = routerOptions || createDefaultRouter(ssrContext).options | |
let routesDirectory = null | |
if (process.server && ssrContext && ssrContext.nuxt && ssrContext.req) { | |
const req = ssrContext.req |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | |
dispatch_group_t group = dispatch_group_create(); | |
dispatch_group_enter(group); // pair 1 enter | |
[self computeInBackground:1 completion:^{ | |
NSLog(@"1 done"); | |
dispatch_group_leave(group); // pair 1 leave | |
}]; | |
dispatch_group_enter(group); // pair 2 enter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in `hg branches |grep -v 'default' |grep -v 'develop' |grep inactive |awk 'NF>1{print $(NF-1)}'`; do hg update -r "$i" && hg commit -m "Closed branch" --close-branch; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface YourViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { | |
UIImageOrientation scrollOrientation; | |
CGPoint lastPos; | |
} | |
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { | |
if (tableView.isDragging) { | |
UIView *myView = cell.contentView; | |
CALayer *layer = myView.layer; | |
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIView *myView = cell.containerView; | |
CALayer *layer = myView.layer; | |
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity; | |
rotationAndPerspectiveTransform.m34 = 1.0 / -1000; | |
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI / 0.3, 0.0f, 1.0f, 0.0f); | |
layer.transform = rotationAndPerspectiveTransform; | |
[UIView animateWithDuration:1.0 animations:^{ | |
layer.transform = CATransform3DIdentity; | |
}]; |