Skip to content

Instantly share code, notes, and snippets.

View Neferetheka's full-sized avatar

Galaad Linosfil Neferetheka

View GitHub Profile
@Neferetheka
Neferetheka / Reflection.php
Created July 23, 2014 13:23
PHP method to create an array from an object using Reflection
/**
* Awesome method to create an array from an object using Reflection. Useful for JSON serialization
* @return array : array of object properties.
*/
public function asArray()
{
$reflectionClass = new ReflectionClass(get_class($this));
$array = array();
foreach ($reflectionClass->getProperties() as $property) {
$property->setAccessible(true);
@Neferetheka
Neferetheka / MultiCorrectActivity.java
Created September 17, 2015 13:57
multiAutoCompleteTextView with autocorrect
multiAutoCompleteTextView.setRawInputType(InputType.TYPE_CLASS_TEXT
|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
|InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
@Neferetheka
Neferetheka / Swype gestures winJS
Created August 10, 2012 08:27
Swype gestures for Windows 8
/*
*Add an event handler to an element to detect pointer down
*Ensure that is a touch event
*MSPointerDown and MSPointerUp are Windows 8/IE10 events. You should look at another code to handle gestures on other browsers
*/
this._element.addEventListener("MSPointerDown", function (e) {
//Touch event
if (e.pointerType == 2) {
context._gestureInfos = new Object();
context._gestureInfos.started = true;
@Neferetheka
Neferetheka / gist:3424009
Created August 22, 2012 09:27
Display last C++ error in Visual Studio output console
DWORD dw = GetLastError();
char *TextSize;
std::printf("Error has occured: ");
FormatMessage(0x00000100 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0,
dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &TextSize, 0, 0);
OutputDebugString((LPCWSTR)TextSize);
@Neferetheka
Neferetheka / gist:3426203
Created August 22, 2012 14:37
Regex to search through html text
//Adapted from http://stackoverflow.com/questions/3460004/regexp-to-search-replace-only-text-not-in-html-attribute
var reg = new RegExp("(?![^<>]*>) *("+search+") *([^ \d])", "g");
var resultsWithoutHTML = text.replace(reg, "toReplace");
@Neferetheka
Neferetheka / Mobile UA detection
Created July 16, 2013 10:18
Allows to detect common mobile platforms
isAndroid = function(){
return navigator.userAgent.toLowerCase().indexOf("android") > -1;
}
isIOS = function(){
return navigator.userAgent.match( /(iPod|iPhone|iPad)/ );
}
isWP = function(){
return navigator.userAgent.indexOf("Windows Phone OS") > -1;
}
isBB = function(){
<main>
<input placeholder="Search, or say Google" x-webkit-speech autocomplete="off" />
<header></header>
<section class="card">
<h1><strong>32 minutes</strong> to Consol Energy Center</h1>
<h2>McKnight Road</h2>
<div class="map"></div>
@Neferetheka
Neferetheka / Read File on Windows Phone
Last active December 20, 2015 18:09
Read a file in assets on Windows Phone
private string GetResourceContent(string path)
{
var resource = App.GetResourceStream(new Uri(path, UriKind.Relative));
StreamReader reader = new StreamReader(resource.Stream, Encoding.UTF8);
return reader.ReadToEnd();
}
@Neferetheka
Neferetheka / TaskHelper
Created August 8, 2013 18:15
TaskHelper for Windows Phone
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
@Neferetheka
Neferetheka / ISHelper.cs
Created August 16, 2013 20:00
Helper to manage Isolated Storage on Windows phone
using System;
using System.IO;
using System.IO.IsolatedStorage;
namespace Tools
{
public abstract class ISHelper
{
private const string directory = "Storage";