Skip to content

Instantly share code, notes, and snippets.

@L3V147H4N
L3V147H4N / Authorize.js
Last active March 17, 2017 18:28
React Role Based Component
import React from 'react';
import {
connect
} from 'react-redux';
import _ from 'lodash';
const Authorize = (allowedRoles) => {
return (WrappedComponent) => {
class WithAuthorization extends React.Component {
constructor (props) {
{
"env": {
//enable nodejs environment
"node": true,
//enable browser environment
"browser": true
},
"globals": {
"Promise" : true
},
@L3V147H4N
L3V147H4N / findDeepValue.js
Created March 10, 2016 14:49
Javascript find Deep Value
function deepFind (path, obj) {
var
paths = path.split('.'),
current = obj || this;
for (var i = 0; i < paths.length; ++i) {
if (current[paths[i]] == undefined) {
return undefined;
} else {
current = current[paths[i]];
@L3V147H4N
L3V147H4N / setDeepValue.js
Last active March 10, 2016 14:51
Javscript Set Deep Value
function setDeepValue (path, value, separator = '.', target) {
path = path.split(separator);
var obj = null;
var res = Object.assign({}, (target ? target : this));
var current = res;
for (var i = 0; i < path.length; i++) {
@L3V147H4N
L3V147H4N / sequenceWithThings.js
Last active February 26, 2016 01:20
Promise Sequence with things to run
function sequenceByArgs (runner, thingsToRun = [], fnName, values = [], method = 'apply') {
return new Promise((resolve, reject) => {
if (thingsToRun.length !== 0) {
var thing = (method === 'apply' && !Array.isArray(thingsToRun[0])) ? new Array(thingsToRun[0]) : thingsToRun[0];
runner[fnName][method](runner, thing)
.then(data => {
values.push(data);
@L3V147H4N
L3V147H4N / sequence.js
Last active February 26, 2016 00:41
Promise Sequence
function promiseSequence (array, values = [], fnName, args = []) {
return new Promise((resolve, reject) => {
if (array.length !== 0) {
array[0][fnName].apply(array[0], args)
.then(data => {
values.push(data);
array.splice(0, 1);
promiseSequence(array, values, fnName, args)
.then(() => {
//#Version 4354 (22/06/2015 18:28) supervisor@GABRIEL-ACER --- Anterior 3917 (11/04/2014 01:07)
//#Include Configuracion
//
DECLARE @Bulto INT
DECLARE @AutoInc INT
DECLARE @PRDLink INT
DECLARE @PRVLink INT
DECLARE @RubLink INT
DECLARE @SRuLink INT
DECLARE @PRDConcepto VARCHAR(30)
@L3V147H4N
L3V147H4N / get database schemas
Created April 27, 2015 19:42
SQL Server Get Database Schemas
SELECT t.name AS TableName,
SCHEMA_NAME(t.schema_id) AS SchemaName,
c.name AS ColumnName,
tp.name as DataType
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
INNER JOIN sys.types tp ON c.system_type_id = tp.system_type_id
WHERE
tp.name <> 'sysname'
ORDER BY TableName;
@L3V147H4N
L3V147H4N / sql_find_duplicates
Created March 18, 2015 17:26
SQL - Find Duplicates By Given Field
SELECT *
FROM Table
WHERE Table.Field IN (
SELECT Table.Field
FROM Table
GROUP BY Table.Field
HAVING COUNT(*) > 1
)
ORDER BY Table.Field
@L3V147H4N
L3V147H4N / gist:a90f088c85cd00fea94c
Last active February 22, 2019 05:48
PHP ANSI to UTF-8
public static function ansiEncode($array = array(), $fields = array()) {
if(!empty($array)) {
for($i = 0; $i < count($array); $i++) {
foreach($fields as $key => $value) {
try {