Skip to content

Instantly share code, notes, and snippets.

View donjajo's full-sized avatar
🏠
Working from home

James John donjajo

🏠
Working from home
View GitHub Profile
@donjajo
donjajo / catch.js
Last active January 8, 2021 13:31
Verify Unicode character on Google's page, to be used on this page - https://support.google.com/merchants/answer/7052112?hl=en
let table = document.getElementsByTagName("table")
tbodies = table[2].tBodies[0].children
for( let tr of tbodies ) { console.log( tr.children[0].textContent == tr.children[0].textContent.replace( /[^a-zA-Z0-9_-]/, "" ), `\nOriginal: ${tr.children[0].textContent}`, `\nSanitized: ${tr.children[0].textContent.replace( /[^a-zA-Z0-9_-]/, "" ) }`, `\nFound:`, tr.children[0].textContent.match(/[^A-Za-z0-9_-]/) ) }
@donjajo
donjajo / google_product_data_specifications.json
Last active January 8, 2021 12:47
JSON format of Google Product Data Specification, as seen here - https://support.google.com/merchants/answer/7052112?hl=en
[
{
"slug": "id",
"description": "Your product’s unique identifier",
"schema": "Product.sku",
"group": "basic"
},
{
"slug": "title",
"description": "Your product’s name",
@donjajo
donjajo / id.c
Created June 13, 2019 22:08
Simple replica of `id` command
#include <stdio.h>
#include <pwd.h>
#include <unistd.h>
#include <stdlib.h>
#include <grp.h>
#include <string.h>
void main( int argc, char *argv[] ) {
struct passwd *user;
struct group *group;
@donjajo
donjajo / list_files.c
Created May 15, 2019 12:43
List files in directory and sub directories with size and permission
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
void list_files();
void main( int argc, char * argv[] ) {
list_files( argv[1], 0 );
@donjajo
donjajo / file_get_contents.c
Last active May 5, 2019 21:12
Replica of file_get_contents() function in PHP
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *file_get_contents();
int main() {
char *str = file_get_contents( "test.txt" );
printf( "%s", str );
free( str );
@donjajo
donjajo / array_pop.c
Last active April 12, 2019 21:03
Finds the non-repeated number in an array
#include <stdio.h>
#include <stdlib.h>
_Bool in_array();
int *pop_array();
void main() {
int numbers[] = { 1, 2, 2, 4, 4, 1, 5, 6, 5 };
int length = sizeof( numbers ) / sizeof( numbers[ 0 ] );
int lucky = 0;
<?php
$numbers = [ 3,3,2,2,56,4,4 ];
$checked = [];
foreach( $numbers as $number ) {
$checked[ $number ] = !empty( $checked[ $number ] ) ? $checked[ $number ] + 1 : 1;
}
asort( $checked );
echo current( array_keys( $checked ) );
<html>
<body>
<stream src="84d67cc5b2639fcbdc25cbc78b5f1268" controls preload autoplay loop mute></stream>
<script data-cfasync="false" defer type="text/javascript" src="https://embed.videodelivery.net/embed/r4xu.fla9.latest.js?video=84d67cc5b2639fcbdc25cbc78b5f1268"></script>
<script>
var firstStreamElement = document.getElementsByTagName('stream')[0];
firstStreamElement.addEventListener( 'play', function( e ) {
e.target.currentTime = 3;
})
@donjajo
donjajo / datamap.react.js
Last active February 19, 2019 10:57
Reactjs Datamap wrapper
import React, { Component } from "react";
import { withScriptjs, withGoogleMap, GoogleMap, Marker } from "react-google-maps";
import Datamap from 'datamaps'
import API from '../../../../api/MapKey';
class Map extends Component {
constructor( props ) {
super( props )
this.state = {
@donjajo
donjajo / s3_dirs.php
Last active October 2, 2018 18:14
Get List of Directories in AWS S3 as array keys. Nested subfolders
<?php
require_once( __DIR__ . '/aws/aws-autoloader.php' );
use Aws\S3\S3Client;
define( 'AWS_S3', [
'key' => '',
'secret' => '',
'bucket' => ''
]);