Skip to content

Instantly share code, notes, and snippets.

View Nicanor008's full-sized avatar
🏹
Focusing

Nicanor Korir Nicanor008

🏹
Focusing
View GitHub Profile
@Nicanor008
Nicanor008 / findAndUpdateDuplicateArrayObject
Created October 30, 2020 05:32
Array objects can be tricky to update. To avoid repetition, here is a snippet to find by key/name and update value.
var data = [
{name:'a',value:'aa'},
{name:'b',value:'bb'}
];
function updateData(obj){
var objFound_bool = false;
for (var i = 0; i < data.length; i++) {
if(obj.name === data[i].name){
objFound_bool = true;
@Nicanor008
Nicanor008 / iconsInInputForm.html
Created August 6, 2020 14:05
How to create icons inside the input without a background image or a third party library.
<style>
.input-container {
position:relative;
display: flex;
}
.input-container img {
position: absolute;
margin-left: 16px;
margin-top: 13px;
}
@Nicanor008
Nicanor008 / DeviceDimensions
Last active July 28, 2020 21:11
Get the current device dimensions. Either width or hight in react
import React, { useEffect, useState } from "react"
function getWindowDimensions() {
const { innerWidth: width, innerHeight: height } = window;
return {
width,
height
};
}
// JS - Email validation in regex
function validateEmail(email) {
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
@Nicanor008
Nicanor008 / postgres-cheatsheet.md
Created January 8, 2019 12:32 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@Nicanor008
Nicanor008 / drf_django
Created January 8, 2019 07:40
Django rest framework views gist
from rest_framework.response import Response
from rest_framework.views import APIView
from . import models
from . import serializers
class GameListCreate(APIView):
def get(self, request, format=None):
games = models.Game.objects.all()
@Nicanor008
Nicanor008 / tdd
Created December 19, 2018 17:22
implementation of TDD
class ViewTestCase(TestCase):
def setUp(self):
self.client = APIClient()
self.user = {'name': 'Nicanor'}
self.response = self.client.post(self.user,format="json")
def test_api_can_create_a_user(self):
self.assertEqual(self.response.status_code, status.HTTP_201_CREATED)
@Nicanor008
Nicanor008 / Option A
Created July 9, 2018 07:10 — forked from anonymous/Option A
3 options for the layout of an activity for a quiz question
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">