Skip to content

Instantly share code, notes, and snippets.

View djalmajr's full-sized avatar

Djalma Júnior djalmajr

View GitHub Profile
@djalmajr
djalmajr / toggleContentEditable.js
Last active August 29, 2015 14:14
Toggle element edit
var el = document.querySelector('.el'),
btn = document.querySelector('.btn-edit');
el.addEventListener('input', function (e) {
console.log(e.currentTarget.textContent);
});
btn.addEventListener('click', function () {
var isEditing = el.getAttribute('contenteditable');
@djalmajr
djalmajr / span-surround.js
Last active August 29, 2015 14:23
Surround letters, words and lines with span
/**
* Wraps a string around each character/letter
*
* @param {string} str The string to transform
* @param {string} tmpl Template that gets interpolated
* @returns {string} The given input as splitted by chars/letters
*/
function wrapChars(str, tmpl) {
return str.replace(/\w/g, tmpl || "<span>$&</span>");
}
Array(numParcelas).join(1).split("").map(n => ...)
Array.apply(null, Array(numParcelas)).map(n => ...)
Array(...Array(numParcelas)).map(n => ...)
@djalmajr
djalmajr / getElementsByAttr.js
Created May 17, 2016 22:33
getElementsByAttr
function getElementsByAttr(attribute, value, parent) {
var matchingElements = [],
allElements = (parent || document).getElementsByTagName("*");
for (var i = 0, n = allElements.length; i < n; i++) {
if (allElements[i].getAttribute(attribute) === value) {
// Element exists with attribute. Add to array.
matchingElements.push(allElements[i]);
}
}
@djalmajr
djalmajr / estados-cidades.json
Created May 21, 2016 13:22 — forked from letanure/estados-cidades.json
JSON estados cidades
{
"estados": [
{
"sigla": "AC",
"nome": "Acre",
"cidades": [
"Acrelândia",
"Assis Brasil",
"Brasiléia",
"Bujari",
@djalmajr
djalmajr / Main.java
Created May 21, 2016 13:24 — forked from JFRode/Main.java
SQL para registro de todos os estados e cidades do Brasil
package jfrode.jsontosql.main;
import java.io.BufferedReader;
import java.io.FileReader;
import org.json.JSONArray;
import org.json.JSONObject;
/**
*
@djalmajr
djalmajr / genymotionwithplay.txt
Created May 24, 2016 20:48 — forked from wbroek/genymotionwithplay.txt
Genymotion with Google Play Services
Download the following ZIPs:
ARM Translation Installer v1.1 (http://www.mirrorcreator.com/files/0ZIO8PME/Genymotion-ARM-Translation_v1.1.zip_links)
Download the correct GApps for your Android version:
Google Apps for Android 6.0 (https://www.androidfilehost.com/?fid=24052804347835438 - benzo-gapps-M-20151011-signed-chroma-r3.zip)
Google Apps for Android 5.1 (https://www.androidfilehost.com/?fid=96042739161891406 - gapps-L-4-21-15.zip)
Google Apps for Android 5.0 (https://www.androidfilehost.com/?fid=95784891001614559 - gapps-lp-20141109-signed.zip)
Google Apps for Android 4.4.4 (https://www.androidfilehost.com/?fid=23501681358544845 - gapps-kk-20140606-signed.zip)
Google Apps for Android 4.3 (https://www.androidfilehost.com/?fid=23060877490000124 - gapps-jb-20130813-signed.zip)
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(" OPR/") >= 0
, isIE = /*@cc_on!@*/false || !!document.documentMode
, isChrome = !!window.chrome && !!window.chrome.webstore;
window.__BrowserDetection = {
// Opera 8.0+
isOpera: isOpera,
// Firefox 1.0+
isFirefox: typeof InstallTrigger !== "undefined",
// At least Safari 3+: "[object HTMLElementConstructor]"
@djalmajr
djalmajr / template.js
Created July 5, 2017 16:45 — forked from katspaugh/template.js
String.prototype.template
String.prototype.template = function (obj) {
return this.replace(
/{{(.+?)}}/g,
function (_, key) { return obj[key] }
)
}
@djalmajr
djalmajr / wall-variation.java
Created September 14, 2017 20:32
RoboCode Robot Wall Variation
package ifal;
import robocode.*;
import java.awt.Color;
import static robocode.util.Utils.normalRelativeAngleDegrees;
// API help : http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html
/**
* RedRibbon - Robô feito por Djalma e Nywton