Skip to content

Instantly share code, notes, and snippets.

View PaulGwamanda's full-sized avatar
💭
Leave the world a little better than you found it

Paul Gwamanda PaulGwamanda

💭
Leave the world a little better than you found it
View GitHub Profile
@PaulGwamanda
PaulGwamanda / app.js
Created January 7, 2024 21:50 — forked from bauefikapa/app.js
Example React Client Kapa AI Streaming
import React, { useState, useEffect } from 'react';
const App = () => {
const [relevantSources, setRelevantSources] = useState([]);
const [answer, setAnswer] = useState('');
const [identifiers, setIdentifiers] = useState(null);
const [error, setError] = useState(null);
const [feedback, setFeedback] = useState(null);
const process_stream = async (response) => {
@PaulGwamanda
PaulGwamanda / hover over section and underline heading
Created April 16, 2020 06:05
hover over section and underline heading
//hover over section and underline heading
section{
h2 {
text-decoration: none;
letter-spacing: 0.15em;
display: inline-block;
padding: 10px 0;
position: relative;
}
@PaulGwamanda
PaulGwamanda / gist:9b56eb04776f053e7a489758f8828857
Created April 15, 2019 18:36
Create new item for every item found in a list
# ie List is a normal list:
# 104.txt
# 105.txt
# 106.txt
# 107.txt
# 108.txt
# When done with code below should give me 5x files with a .txt extension, ie 104.txt, 105.txt. Can be any file ext.
List = open("64-120/rename.txt")
@PaulGwamanda
PaulGwamanda / umbraco-pagination.cshtml
Created February 27, 2019 09:53
This is an Umbraco 7 pagination script for blog posts/articles, uses bootstrap to paginate at the bottom of articles
<div class="articles-list mb-5">
<div class="row">
@{
int pageSize = 2; // How many items per page
int page; // The page we are viewing
/* Set up parameters */
if (!int.TryParse(Request.QueryString["page"], out page))
{
@PaulGwamanda
PaulGwamanda / SCSS-support-to-create-react-app
Created November 22, 2018 09:30
Add SCSS support to create-react-app
//-------------------- Add SCSS Loaders -------------------------//
// In order to access the config files, we would runnpm run eject to eject the build scripts from starter app. You'll be asked for approval because the action is // permanent. Once this command has successfully run, you should see a config and scripts folder created. They contain all the build scripts necessary for // building the started app. Among them is the webpack.config.dev.js and webpack.config.prod.js files, which is our focus.
//
// Also note that npm run eject updates your dependencies with other packages which it has previously abstracted from you. You can view those new dependencies in // your package.json.
// First run npm i sass-loader and npm i node-sass —save to install sass-loader to help in compiling your scss to css.
// Next, edit the webpack.config.dev.js in the config folder as follows. Add the loaders to configure the webpack, to compile our scss files.
// Add this after the loader: require.resolve('postcss-loader') dec
@PaulGwamanda
PaulGwamanda / rename.py
Created November 16, 2018 13:39
Python script to rename files in directory, transforming spaces to hyphens and the chars to lowercase
import os
"""
Renames the filenames within the same directory to be Unix friendly
(1) Changes spaces to hyphens
(2) Makes lowercase (not a Unix requirement, just looks better ;)
Usage:
python rename.py
"""
@PaulGwamanda
PaulGwamanda / findReplace.py
Created October 12, 2018 10:46
Python program to find replace and clean files in directory
def findReplace(directory, find, replace, filePattern):
for path, dirs, files in os.walk(os.path.abspath(directory)):
for filename in fnmatch.filter(files, filePattern):
filepath = os.path.join(path, filename)
with open(filepath) as f:
s = f.read()
s = s.replace(find, replace)
with open(filepath, "w") as f:
f.write(s)
MYPATH = "folder/folder"
@PaulGwamanda
PaulGwamanda / png_to_numpy_array.py
Created October 11, 2018 08:37
Convert PNG images to numpy array (NPZ) for machine learning
from __future__ import print_function
from __future__ import absolute_import
from distutils.dir_util import copy_tree
import os
import sys
import glob
import json
import re
import shutil
@PaulGwamanda
PaulGwamanda / related-posts.php
Last active October 4, 2018 12:56
Wordpress related posts
@PaulGwamanda
PaulGwamanda / WP_Query_Columns.php
Last active October 3, 2018 11:06
How to split a loop into multiple columns - WP_Query_Columns - Columns for the loop. - http://wordpress.stackexchange.com/q/9308/178
// How to split a wordpress bootstrap loop into multiple columns
/** This goes into template **/
<?php $the_query = new WP_Query('cat=1&showposts=50&orderby=title&order=asc');?>
<?php foreach(new WP_Query_Columns($the_query, 10) as $column_count) : ?>
<ul>
<?php while ($column_count--) : $the_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>