Skip to content

Instantly share code, notes, and snippets.

@error454
error454 / gist:1202171
Created September 7, 2011 23:38
Java random delay
void randomDelay(float min, float max){
int random = (int)(max * Math.random() + min);
try {
Thread.sleep(random * 1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@error454
error454 / incrementString.js
Created November 11, 2011 19:59
Increment ASCII value of each character in a string
var incrementString = function(string, count){
var newString = [];
for(var i = 0; i < string.length; i++){
newString[i] = String.fromCharCode(string[i].charCodeAt() + count);
}
newString = newString.join('');
console.log(newString);
return newString;
}
@error454
error454 / localizationHelper.java
Created November 23, 2011 03:41
Reverse numbers for R to L languages such as Hebrew
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LocalizationHelper {
//Any series of 1-2 digits followed by a colon followed by 1-2 digits
private static Pattern timePat = Pattern.compile("\\d{1,2}:\\d{1,2}");
/// <summary>
/// Regular expression built for C# on: Tue, Nov 22, 2011, 07:58:22 PM
@error454
error454 / gist:1448313
Created December 8, 2011 20:01
Simple Function Timing for C/C++
//The includes required
#include "time.h"
#include "stdio.h"
FILE *logfile;
/*
* Compares two time intervals and returns the time
* difference in milliseconds.
*/
@error454
error454 / gist:1754202
Created February 6, 2012 19:20
Bash DNS resolution timer
#!/bin/bash
#Sleep interval
S=$1
#filename suffix
suffix="s.log"
while(true)
do
Single-line version of pattern:
(?i)\b((?:http(?:s)?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.][a-z]{2,4})(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\)){0,}(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
Extended version of same pattern:
(?i) #Ignore Case
\b
( # Capture 1: entire matched URL
(?:
http(?:s)?: # http: and https: only
@error454
error454 / gist:3229018
Created August 1, 2012 17:27
QR Code WiFi Scheme Regex

QR Code WiFi Scheme Regexs of Extreme Awesomeness

A few regular expressions to parse WIFI schemes such as:

WIFI:T:WEP;S:test;P:rainbows\;unicorns\:jedis\,ninjas\\ secure;;

Network Type

###Raw (?<=T:)[a-zA-Z]+(?=;)

@error454
error454 / gist:3687194
Created September 9, 2012 20:49
on{X} Send Location via Google Maps
var numbers = new Array("5035551234", "5035551235", "");
var messageText = "where?";
console.log('Started script: Send location to number using google maps');
// Register callback on sms received event
device.messaging.on('smsReceived', function (sms) {
//Allow using +1 or not +1 in phone number definition
var sanitizedFrom = sms.data.from;
@error454
error454 / gist:3687788
Created September 9, 2012 22:52
on{X} Morning Umbrella & Coat Check
var time = "6:30 AM";
var temperatureBar = "below";
var temperature = "55";
var unitType = "i" /* Fahrenheit */;
var weatherCondition = "rainy";
function showForecast() {
// Get the current location
var locationListener = device.location.createListener('CELL', 2);
locationListener.on('changed', function (locSignal) {
@error454
error454 / gist:3815996
Created October 2, 2012 03:31
Keyboard event handling blog sample
--------------------------------------------------------------------------------
function InputAI.onKeyboardKeyDown ( kKeyCode )
--------------------------------------------------------------------------------
if( kKeyCode == input.kKeyW )
then
--handle W
elseif( kKeyCode == input.kKeyA )
then
--handle A