Skip to content

Instantly share code, notes, and snippets.

View marcelaraujo's full-sized avatar

Marcel Araujo marcelaraujo

  • Lisbon/PT
  • 05:10 (UTC +01:00)
View GitHub Profile
@marcelaraujo
marcelaraujo / continue.js
Created March 10, 2015 14:27
Javascript labeled loop
var i = 0,
j = 8;
checkiandj: while (i < 4) {
console.log("i: " + i);
i += 1;
checkj: while (j > 4) {
console.log("j: "+ j);
j -= 1;
@marcelaraujo
marcelaraujo / gist:0de8e9ddc776e8a628b6
Created March 16, 2015 14:13
Pack and Unpack javascript strings
var pack = function pack (bytes) {
var str = "";
for(var i = 0; i < bytes.length; i += 2) {
var char = bytes[i] << 8;
if (bytes[i + 1])
char |= bytes[i + 1];
str += String.fromCharCode(char);
}
return str;
};
@marcelaraujo
marcelaraujo / gist:d50754ad2ca3599bf548
Created March 16, 2015 14:13
String to byte array
function stringToByteArray(str) {
var b = [], i, unicode;
for(i = 0; i < str.length; i++) {
unicode = str.charCodeAt(i);
// 0x00000000 - 0x0000007f -> 0xxxxxxx
if (unicode <= 0x7f) {
b.push(String.fromCharCode(unicode));
// 0x00000080 - 0x000007ff -> 110xxxxx 10xxxxxx
} else if (unicode <= 0x7ff) {
b.push(String.fromCharCode((unicode >> 6) | 0xc0));
// React Class template with inlined documentation from
// http://facebook.github.io/react/docs/component-specs.html
var component = React.createClass({
/***** Core Methods *****/
render: function () {
// Returns ReactComponent
/**
* This are a collection of examples for C 201.
* These combine concepts you may or may not be
* familiar with and are especially useful for
* students new to C. There is a lot of really
* cool stuff you can do in C without any cool
* languages.
*
* This is file in particular is an introduction
* to fun function usage in C.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Clash of Clans Auto Tool for Genymotion (VirtualBox Android VM)
"""
import os
import sys
import virtualbox
import subprocess
import cv2.cv as cv
@marcelaraujo
marcelaraujo / gist:5127dd0d922652714d55
Created May 14, 2015 13:05
Doctrine 2 - SQL Full Logger
<?php
namespace Common\Doctrine;
use Doctrine\DBAL\Logging\SQLLogger;
use Monolog\Logger;
class EchoSQLLogger implements SQLLogger
{
var fn = function(arg1, arg2) {
var str = '<p>aap ' + this.noot + ' ' + arg1 + ' ' + arg2 + '</p>';
document.body.innerHTML += str;
};
var context = {
'noot': 'noot'
};
var args = ['mies', 'wim'];
// Calls a function with a given 'this' value and arguments provided individually.
function wrapSpan(node, index) {
if(node.nodeName === '#text') {
var text = node.textContent;
var s = document.createElement('span');
s.textContent = text;
node.parentElement.insertBefore(s, node.parentElement.childNodes[index]);
node.remove();
} else {
//To run Q.js examples:
// 1. Open a new browser tab in Chrome and turn on developer toolbar.
// 2. Copy/Paste this gist in the console and hit enter to run all the snippets.
// Based on the inspiration from samples @ https://github.com/kriskowal/q
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////