Skip to content

Instantly share code, notes, and snippets.

@alcedo
alcedo / JavaSnippets.java
Last active February 8, 2018 23:38
Java function snippets, Matrix, LCM, GCD
// used to print format print. %n is new line. dont use \n
// http://docs.oracle.com/javase/tutorial/java/data/numberformat.html
System.out.format("The value of sum is: %.2f%n", 4650/100);
//Rotates a matrix right
public static void rotateRight(char[][] matrix) {
int cols = matrix[0].length;
int rows = matrix.length;
@alcedo
alcedo / FastInputOutput.java
Last active December 21, 2015 22:38
Fast I/O utility classes for UVa online
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;
@alcedo
alcedo / Recursive Backtracking.txt
Last active December 22, 2015 12:28
Recursive Backtracking:
Recursive Backtracking:
usually involves a for loop + a recursion. (the for loop acts as a backtracking mechanism)
The requirements for a recursive solution are met in these ways.
.The problem is made smaller by taking one step in the space - by making one move.
.The base case occurs when the property has been fully satisfied and we arrive at the exit.
.The partial results are combined by putting the steps together in a way that is appropriate (perhaps printing them, or returning them as a list to some other program).
*important things to note: The base case is *usually* the solution to the problem.
@alcedo
alcedo / gist:6576530
Last active December 23, 2015 03:49
Angular JS Notes
AngularJS: $watch, $digest and $apply
Some Guidelines For Use:
$watch
DO use $watch in directives to update the DOM when a $scope value changes.
DON'T use $watch in a controller. It's hard to test and completely unnecessary in almost every case. Use a method on the scope to update the value(s) the watch was changing instead.
$digest/$apply
DO use $digest/$apply in directives to let Angular know you've made changes after an asynchronous call, such as a DOM event.
DO use $digest/$apply in services to let Angular know some asynchronous operation has returned, such as a WebSocket update, or an event from a 3rd party library like Facebook API.
@jbenet
jbenet / simple-git-branching-model.md
Last active November 9, 2024 04:55
a simple git branching model

a simple git branching model (written in 2013)

This is a very simple git workflow. It (and variants) is in use by many people. I settled on it after using it very effectively at Athena. GitHub does something similar; Zach Holman mentioned it in this talk.

Update: Woah, thanks for all the attention. Didn't expect this simple rant to get popular.

@alcedo
alcedo / Unix_unix_notes.sh
Created October 10, 2013 08:58
Unix notes
### How to change permissions of all files in a dir using XARGS
[root@abc installers]# ls | xargs -Ifile chmod 777 file
[root@abc installers]# ls -rlt
total 446676
-rwxrwxrwx 1 abc abc 30537780 Oct 8 08:18 hcatalog-0.11.0.1.3.2.0-111.tar.gz
-rwxrwxrwx 1 abc abc 14492759 Oct 8 08:20 Python-2.7.5.tgz
[root@abc installers]# ls | xargs -I{} chmod 777 {}
@alcedo
alcedo / q1_1.py
Last active April 16, 2022 10:34
Cracking the coding interview
#Q 1.1, implement an algo to determine if a string has all unique chars. What if you cannot use additional DS?
http://repl.it/N28/1
def is_unique_chars(my_string):
my_string_list = sorted(my_string)
seen = set()
for c in my_string_list:
if c in seen:
@sivel
sivel / better-ssh-authorized-keys-management.md
Last active October 3, 2024 16:46
Better SSH Authorized Keys Management

Better SSH Authorized Keys Management

A seemingly common problem that people encounter is how to handle all of your users authorized_keys file.

People struggle over management, ensuring that users only have specific keys in the authorized_keys file or even a method for expiring keys. A centralized key management system could help provide all of this functionality with a little scripting.

One piece of functionality overlooked in OpenSSH is the AuthorizedKeysCommand configuration keyword. This configuration allows you to specify a command that will run during login to retrieve a users public key file from a remote source and perform validation just as if the authorized_keys file was local.

Here is an example directory structure for a set of users with SSH public keys that can be shared out via a web server:

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?