Skip to content

Instantly share code, notes, and snippets.

View 0ct0d4n's full-sized avatar
🦆
#stayHome

Daniel 0ct0d4n

🦆
#stayHome
  • Software Engineer
  • San Antonio, Texas
View GitHub Profile
@0ct0d4n
0ct0d4n / zend_routematch_from_servicemanager_inside_factory.php
Last active October 6, 2016 19:14
Get RouteMatch object from ServiceManager inside a factory in ZendFramework 2
<?php
// ...
public function createService(ServiceLocatorInterface $serviceLocator)
{
$sm = $serviceLocator->getServiceLocator();
$routeMatch = $sm->get('application')->getMvcEvent()->getRouteMatch();
$param = $routeMatch->getParam('id', 0);
}
@0ct0d4n
0ct0d4n / wget _http_directory_with_files.sh
Created October 7, 2016 23:08
Download an entire directory using wget
wget -r --no-parent http://domain.com/any/directory/with/files
@0ct0d4n
0ct0d4n / DAOTestRule.java
Created December 30, 2016 14:41
JUNIT DAOTestRule For Dropwizard-0.7.1
package dropwizardold;
import com.google.common.base.Throwables;
import io.dropwizard.logging.BootstrapLogging;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AvailableSettings;
@0ct0d4n
0ct0d4n / timestamp-Algorithm.js
Created January 1, 2017 17:47
Timestamp algorithm based on UNIX TIMESTAMP
/**
* TIMESTAMP Algorithm.
* @author Daniel Vera Morales
*
* WARNING: This script is for demonstration and educational purpose, it is not a stable version.
*/
// Testit using: http://www.unixtimestamp.com/index.php
// Explanation taken from: http://www.devshed.com/c/a/administration/unix-time-format-demystified/
@0ct0d4n
0ct0d4n / clock.html
Created January 1, 2017 17:53
Current UTC Live Time Clock
<div class="bigtime shadow rounded bgwgr"><span id="time" class="fontbig">00:00:00</span>
<script src="clock.js"></script>
<script src="clockinit.js"></script>
@0ct0d4n
0ct0d4n / resourceFixture.java
Created January 3, 2017 17:59
Methods to get Resources or Fixtures in java
/**
* Resource resolution
*/
private String getFixture(String name) throws IOException {
String result = "";
ClassLoader classLoader = getClass().getClassLoader();
try {
@0ct0d4n
0ct0d4n / index.html
Created January 18, 2017 15:36
Push a module to a stack before RequireJS is loaded, then when RequireJS get loaded the modules will be invoked.
<script>
ministack.push(function ()
{
require(['anyMOD'], function(anyMOD){
});
});
</script>
@0ct0d4n
0ct0d4n / equality.md
Last active January 25, 2017 04:12
Equality in java

"==" Compares the bits in two variables. Check if two variables are the same. Zeros on the left end don't matter.

int a = 2; byte b = 3; (a == b); // true

.equals() Check the equality of two objects that are different in the heap but they are the same type. It depends on what makes sense for that particular type.

String x = "a";

@0ct0d4n
0ct0d4n / reusableExceptions.md
Created April 20, 2017 15:59 — forked from 7yl4r/reusableExceptions.md
info on Java built-in exceptions from perspective of developer looking to reuse built-in exceptions

organized by estimated utility

IllegalArgumentException

Thrown to indicate that a method has been passed an illegal or inappropriate argument.

IndexOutOfBoundsException

Thrown to indicate that an index of some sort (such as to an array, to a string, or to a vector) is out of range.

ArithmeticException

Thrown when the requested mathematical operation is non-sensical or impossible.

@0ct0d4n
0ct0d4n / asciirandom.js
Created July 20, 2017 16:52
RANDOM ASCII NAME BASED ON TIMESTAMP
var name = "";
var timest = (Math.trunc(Math.round(new Date().getTime()/1000))) + "";
for (var i = 0, len = timest.length; i < len; i++) {
var current = parseInt(timest[i]);
var ascii = Math.floor(Math.random() * (7-6+1)) + 6;
name+=String.fromCharCode(ascii+""+current) + "";
}
alert(name);