Skip to content

Instantly share code, notes, and snippets.

View SleeplessByte's full-sized avatar
💎
💎 💎 💎

Derk-Jan Karrenbeld SleeplessByte

💎
💎 💎 💎
View GitHub Profile
@SleeplessByte
SleeplessByte / detect.java
Created November 5, 2014 22:08
Credit Card Detection
public static CardType fromCardNumber( String cardNumber ) {
if ( cardNumber == null )
return CardType.Null;
if ( cardNumber.matches( "^4[0-9]*$" ) )
return CardType.Visa;
if ( cardNumber.matches( "^5[1-5][0-9]*$" ) )
return CardType.MasterCard;
if ( cardNumber.matches( "^3[47][0-9]*$" ))
return CardType.Amex;
if ( cardNumber.matches( "^6(?:011|5)[0-9]*$" ))
@SleeplessByte
SleeplessByte / rfc4122-uuid.js
Created April 29, 2014 19:12
RFC4122 compliant UUID in Javascript (by broofa)
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
@SleeplessByte
SleeplessByte / silly.js
Created February 3, 2014 18:40
Javascript is silly
"J"+(([]===[])+/-/)[1]+/\[[^1]+\]/[([]+![])[1<<1<<1]+(/|/[(1+{})[1+11>>>1]+[[]+{}][+!1][1]+([]+1/[])[1<<1>>1]+([1<1]+[])[1+11>>>1+1]+[[!!1]+1][+[]][1-1]+([]+!!/!/)[1|1]+(/1/[1]+[])[!1%1]+(-{}+{})[-1+1e1-1]+(1+[!!1])[1]+([]+1+{})[1<<1]+[!!/!!/+[]][+[]][1&1]]+/=/)[1e1+(1<<1|1)+(([]+/-/[(!!1+[])[1>>1]+(!!1+[])[1<<1^1]+(!1+[])[1|1<<1]+(!!1+[])[1^1]])[1^1]==+!1)]+(!![]+{})[1|1<<1]+[1+{}+1][!1+!1][(11>>1)+1]](([]+/-/[(!!1+[])[1>>1]+(!!1+[])[1<<1^1]+(!1+[])[1|1<<1]+(!!1+[])[1^1]]))[1&.1][11>>>1]+(([]===[])+/-/)[1]+([1<1]+[])[1+11>>>1+1]+(1+{})[1+11>>>1]+[!!/!!/+[]][+[]][1&1]+/\[[^1]+\]/[([]+![])[1<<1<<1]+(/|/[(1+{})[1+11>>>1]+[[]+{}][+!1][1]+([]+1/[])[1<<1>>1]+([1<1]+[])[1+11>>>1+1]+[[!!1]+1][+[]][1-1]+([]+!!/!/)[1|1]+(/1/[1]+[])[!1%1]+(-{}+{})[-1+1e1-1]+(1+[!!1])[1]+([]+1+{})[1<<1]+[!!/!!/+[]][+[]][1&1]]+/=/)[1e1+(1<<1|1)+(([]+/-/[(!!1+[])[1>>1]+(!!1+[])[1<<1^1]+(!1+[])[1|1<<1]+(!!1+[])[1^1]])[1^1]==+!1)]+(!![]+{})[1|1<<1]+[1+{}+1][!1+!1][(11>>1)+1]](([]+/-/[(!!1+[])[1>>1]+(!!1+[])[1<<1^1]+(!1+[])[1|1<<1]+(!!1+[])[
@SleeplessByte
SleeplessByte / .gitattributes
Last active February 3, 2021 14:57
.gitattributes that will make development on Windows Great Again
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto
# Force the following filetypes to have unix eols, so Windows does not break them
*.* text eol=lf
# Windows forced line-endings
/.idea/* text eol=crlf
@SleeplessByte
SleeplessByte / .gitignore
Created September 17, 2013 00:58
Comprehensive Android git ignore
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
@SleeplessByte
SleeplessByte / resize_chart_canvas.js
Created May 26, 2013 19:46
Canvas resizer for chart with debouncing, so chart or canvas doesn't crash.
$(document).ready( function(){
// Thank you underscorejs
var debounce = function(func, wait, immediate) {
var timeout, result;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) result = func.apply(context, args);
@SleeplessByte
SleeplessByte / do_prepared_query.php
Created April 30, 2013 18:20
Executes a prepared query. Provide with a query. Use ? in the query for bind locations. Types is a string where its length equals the values array size. Returns the results in an associative array, insert id, NULL or success boolean.
<?php
/**
* Executes a prepared query
*
* @param string $query the query to execute
* @param string $types the types of the bind (s: string or d: integer for each value)
* @param mixed[] $values array of values
* @param string $error referenced error variable
* @returns null|boolean|integer|mixed[] the results
*/
@SleeplessByte
SleeplessByte / regex_attributes.php
Created January 30, 2013 16:22
Reads out attributes foo="bar" octocat as two elements (foo => bar and octocat => )
<?php
function regex_attributes( &$element ) {
$matches = array();
$pattern = '/\s*(?P<key>[^\s=\'"]+)(?:=(?:([\'"])(?P<value>[^\'"]+)[\'"])|\s|$)\s*/sm';
if ( !preg_match_all( $pattern, $element->attributes_raw, $matches, PREG_OFFSET_CAPTURE ) )
return;
foreach ( $matches[0] as $key => $match )
$element->attributes[ $matches['key'][$key][0] ] = $matches['value'][$key][0];
}
@SleeplessByte
SleeplessByte / regex_nested.php
Last active December 11, 2015 23:08
Matches nested tags such as [foo attr="data" loose ][foo]inner content[bar invisible="true"/][/foo][bar]lalala[/bar][/foo][foo]love[/foo] correctly. Simply recall on element->inner_content for recursive processing.
<?php
function regex_nested( $content ) {
$pattern = "/\[(?P<type>[^\]\s]+)(?P<props>[^\]]*?)((?P<tagclose>\s*\/\])|".
"(\](?P<inner>([^\[]*|\<\!\-\-.*?\-\-\>|(?R))*)\[\/\\1\s*\]))/sm";
if ( !preg_match_all($pattern, $content, $matches, PREG_OFFSET_CAPTURE) )
return $content;
$elements = array();
foreach ( $matches[0] as $key => $match ) {
array_push( $elements, (object)array(
@SleeplessByte
SleeplessByte / css_ie7_hacks.css
Created January 15, 2013 21:19
CSS Hacks for Internet Explorer 7. Currently has: inline-block-hack
.inline-block-hack {
/* Other css */
zoom:1; /* << sets has layout */
*display:inline; /* << but inline (with layout = inline-block) */
}