Skip to content

Instantly share code, notes, and snippets.

@chris-carneiro
chris-carneiro / .htaccess
Last active August 9, 2017 09:22
.htaccess that makes apache return "not found" for requests that either lead to a 404 or 403.
ErrorDocument 404 "Not found" Or http://yourdomain.com ## Redirects 404 Error to home page
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/(.*)$ - [R=404,L] ## Returns Error 404 when trying to access a subfolder
## Returns 404 when trying to access the current .htaccess file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(htpasswd|htaccess|aahtpasswd).*\ HTTP/ [NC]
RewriteRule .? - [R=404,NS,L]
@chris-carneiro
chris-carneiro / httpd.conf
Last active August 9, 2017 09:15
Secured apache configuration
######## Security ########
## Silents ServerSignature response
ServerSignature Off
ServerTokens Prod
<IfModule mod_headers.c>
## Forces httpOnly and Secure Cookies - Mitigate XSS Attacks
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
@chris-carneiro
chris-carneiro / CorruptedTimeApproximationHelper.java
Last active January 5, 2018 10:56
API used to approximate a time [hh:mm] in seconds that was mistakenly multiplied by 24.
/**
* Approximates the minutes given a time in seconds that was mistakenly multiplied by 24.<BR/>
* Here is the wrong formula used in the first place. It was used to supposedly calculate a time [hh:mm] in seconds:<BR/>
* <pre>hourOfDay * 24 * 3600 + minute * 60</pre>
* Here's the formula we've come up with to approximate the minutes:<BR/>
* <pre>m ~= (x/60) - (1440*E(x/86400))</pre>
* Where x is the time in seconds and E(h) is the hours rounded to floor.
*
* @param seconds time [hh::mm] in seconds that was multiplied by 24.
* @return int
@chris-carneiro
chris-carneiro / AutoScrollHelper.java
Created January 17, 2018 16:45
Endless autoscrolling for viewPager
public static ObjectAnimator scrollDownSmoothlyIndefinitely(@NonNull WeakReference<NestedScrollView> scrollViewRef, int scrollingDuration) {
NestedScrollView scrollView = scrollViewRef.get();
if (scrollView != null) {
final ObjectAnimator animScrollDown = ObjectAnimator.ofInt(scrollView, "scrollY",
scrollView.getChildAt(0).getHeight());
animScrollDown.setInterpolator(new LinearInterpolator());
animScrollDown.setDuration(scrollingDuration);
@chris-carneiro
chris-carneiro / link-spring-dao-jpa.txt
Last active March 14, 2018 15:58
[LINKS] [Spring]: DAO : JPA
COMPILATION_UNIT -> COMPILATION_UNIT [6:0]
|--BLOCK_COMMENT_BEGIN -> /* [1:0]
| |--COMMENT_CONTENT -> \ncom.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheckTest$JavadocCatchCheck\n\n [1:2]
| `--BLOCK_COMMENT_END -> */ [4:0]
|--PACKAGE_DEF -> package [6:0]
| |--ANNOTATIONS -> ANNOTATIONS [6:54]
| |--DOT -> . [6:54]
| | |--DOT -> . [6:46]
| | | |--DOT -> . [6:39]
| | | | |--DOT -> . [6:28]
COMPILATION_UNIT -> COMPILATION_UNIT [6:0]
|--BLOCK_COMMENT_BEGIN -> /* [1:0]
| |--COMMENT_CONTENT -> \ncom.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheckTest$JavadocCatchCheck\n\n [1:2]
| `--BLOCK_COMMENT_END -> */ [4:0]
|--PACKAGE_DEF -> package [6:0]
| |--ANNOTATIONS -> ANNOTATIONS [6:54]
| |--DOT -> . [6:54]
| | |--DOT -> . [6:46]
| | | |--DOT -> . [6:39]
| | | | |--DOT -> . [6:28]