Skip to content

Instantly share code, notes, and snippets.

View bhrott's full-sized avatar
⚔️
killing zombies

Ben-Hur Santos Ott bhrott

⚔️
killing zombies
View GitHub Profile
@bhrott
bhrott / getQueryStringValueByName.js
Created September 18, 2015 18:52
Get value from url querystring by name
function getQueryStringValueByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
@bhrott
bhrott / arrayContains.extensions.js
Created September 18, 2015 19:08
Function to check if an object is in the array
Array.prototype.contains = function (needle) {
for (i in this) {
if (this[i] == needle) return true;
}
return false;
}
@bhrott
bhrott / validateCPF.js
Last active September 18, 2015 19:19
Function to validate CPF documents
function validateCPF(cpf) {
if (cpf == "") {
return true;
}
cpf = cpf.replace(/\./gi, "").replace(/-/gi, "");
var isValid = true;
var sum;
var rest;
sum = 0;
@bhrott
bhrott / removeNotNumbers.js
Created September 18, 2015 19:23
Function to remove non number characters form a text.
function removeNotNumbers(text) {
if(text) {
text.replace(/[^0-9]/g, '');
}
return text;
}
@bhrott
bhrott / pull_repositories.sh
Created June 8, 2016 00:22
Pull Repositories in Folder
#!/bin/sh
for repo in folder1 folder2 folder3; do
echo UPDATE REPO ${repo}
(cd "${repo}" && git checkout master && git pull origin master)
done
@bhrott
bhrott / clone_repositories.sh
Created June 24, 2016 02:28
SH: Clone Multiple Repositories Repositories
#!/bin/sh
# Clone multiple repositories.
echo "=== CLONENATOR ==="
array=( "https://github.com/angular/angular.git"
"https://github.com/nodejs/node.git" )
for element in ${array[@]}
@bhrott
bhrott / nginxproxy.md
Created August 16, 2016 22:00 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@bhrott
bhrott / nodejs-tcp-example.js
Created November 10, 2016 23:21 — forked from tedmiston/nodejs-tcp-example.js
Node.js tcp client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@bhrott
bhrott / AndroidOpenSettingsPage.java
Last active November 16, 2016 11:54
React Native : Android : Open Settings Page
@ReactMethod
public void openSettingsPage() {
final Intent i = new Intent();
i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setData(Uri.parse("package:" + getReactApplicationContext().getPackageName()));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
getReactApplicationContext().startActivity(i);
@bhrott
bhrott / AndroidCheckLocationEnableState.java
Created November 16, 2016 11:53
React Native : Android : Check Location Enable State
@ReactMethod
public void isLocationEnabled(Promise promise) {
try {
Boolean permissionIsGranted = ContextCompat.checkSelfPermission( getReactApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION ) == PackageManager.PERMISSION_GRANTED;
final LocationManager manager = (LocationManager) getReactApplicationContext().getSystemService( Context.LOCATION_SERVICE );
Boolean gpsIsEnabled = manager.isProviderEnabled( LocationManager.GPS_PROVIDER );
Boolean isEnabled = permissionIsGranted && gpsIsEnabled;
promise.resolve(isEnabled);