I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!
\
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 AppKit | |
let app = NSApplication.shared | |
app.setActivationPolicy(.regular) | |
let window = NSWindow( | |
contentRect: NSMakeRect(0, 0, 640, 480), | |
styleMask: [.titled, .closable], | |
backing: .buffered, | |
defer: 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
> Thank you for reaching out to Autonomous! I am sorry to hear that you are having some trouble with your SmartDesk | |
> but I will be glad to assist. It sounds like your system needs a "hard reset" can I please have you follow these | |
> steps thoroughly. | |
Reset Steps: | |
1. Unplug the desk for 20 seconds. Plug it back in. Wait a full 20 seconds. | |
2. Press the up and down buttons until the desk lowers all the way and beeps or 20 seconds pass. | |
3. Release both buttons. | |
4. Press the down buttons until the desk beeps one more time or 20 seconds pass. |
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
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
public static String getForegroundProcess(Context context) { | |
String topPackageName = null; | |
UsageStatsManager usage = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE); | |
long time = System.currentTimeMillis(); | |
List<UsageStats> stats = usage.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000*1000, time); | |
if (stats != null) { | |
SortedMap<Long, UsageStats> runningTask = new TreeMap<Long,UsageStats>(); | |
for (UsageStats usageStats : stats) { | |
runningTask.put(usageStats.getLastTimeUsed(), usageStats); |
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
From 0dbaf602ac5f11356a192eb2bd388d0e29802848 Mon Sep 17 00:00:00 2001 | |
From: TheStrix <parthbhatia98@gmail.com> | |
Date: Mon, 30 Mar 2015 11:35:33 -0400 | |
Subject: [PATCH] Implement kexec-hardboot | |
"Allows hard booting (i.e., with a full hardware reboot) to a kernel | |
previously loaded in memory by kexec. This works around the problem of | |
soft-booted kernel hangs due to improper device shutdown and/or | |
reinitialization." | |
More info in /arch/arm/Kconfig. |
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 android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener { | |
public static String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName(); | |
private int previousTotal = 0; // The total number of items in the dataset after the last load | |
private boolean loading = true; // True if we are still waiting for the last set of data to load. | |
private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more. | |
int firstVisibleItem, visibleItemCount, totalItemCount; |
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
/* | |
* Copyright (C) 2014 skyfish.jy@gmail.com | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
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
#!/usr/bin/env node | |
// Solve the "Coin Change" problem using a bottom-up dynamic programming | |
// approach. The time complexity is O(n * coins.length) since we have a nested | |
// loop. The storage complexity is the same, as we store a matrix. | |
// | |
// * `coins` is an array of the coin values, eg. [ 1, 2, 3 ]. We assume it | |
// to be non-empty. | |
// * `n` is the amount, eg. 4 cents. | |
// |
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
/** | |
* In this code we have a very large array called arr, and very large set of operations | |
* Operation #1: Increment the elements within range [i, j] with value val | |
* Operation #2: Get max element within range [i, j] | |
* Build tree: build_tree(1, 0, N-1) | |
* Update tree: update_tree(1, 0, N-1, i, j, value) | |
* Query tree: query_tree(1, 0, N-1, i, j) | |
* Actual space required by the tree = 2*2^ceil(log_2(n)) - 1 | |
*/ |
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
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
NewerOlder