Skip to content

Instantly share code, notes, and snippets.

@engine-andre
engine-andre / replace.js
Created July 16, 2013 14:32
replace all non-numeric chars from javascript string
"test-.,.§$§)$)165".replace(/\D/g,''); //165
@engine-andre
engine-andre / MainActivity.java
Created June 21, 2013 13:42
android phonegap load files from other folders then www/assets. fix for "Unknown chromium error: -6"
public class FooBarApp extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
this.init();
this.appView.clearCache(true);
@engine-andre
engine-andre / get_code_of_function.php
Created June 13, 2013 10:33
get code string from an function
$func = new ReflectionFunction('myfunction');
$filename = $func->getFileName();
$start_line = $func->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block
$end_line = $func->getEndLine();
$length = $end_line - $start_line;
$source = file($filename);
$body = implode("", array_slice($source, $start_line, $length));
print_r($body);
@engine-andre
engine-andre / object_to_array.php
Created June 13, 2013 09:35
convert a object to array
function object_to_array($base) {
$base = (array) $base;
foreach ($base as $key => $value) {
if (is_array($value) || is_object($value)) {
$base[$key] = object_to_array($value);
}
}
@engine-andre
engine-andre / case_in_select.sql
Created June 12, 2013 09:20
Case in MySQL Select
SELECT
CASE
WHEN end_date > UNIX_TIMESTAMP() THEN 'run'
ELSE 'stop'
END AS status
FROM
foobar
@engine-andre
engine-andre / var_in_statement.sql
Created June 12, 2013 09:18
Create var in MySQL Statement
SELECT
fb.foo,
fb.bar
FROM
(SELECT @foobar:=0) switchable_var,
foobar fb
WHERE
fb.status = @foobar