Skip to content

Instantly share code, notes, and snippets.

View MillerAdulu's full-sized avatar
💭
I will be slow to respond.

Miller Adulu MillerAdulu

💭
I will be slow to respond.
View GitHub Profile
@mathewbyrne
mathewbyrne / slugify.js
Created October 12, 2011 04:34
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@cole007
cole007 / digitalocean.md
Last active November 22, 2023 16:54
Digital Ocean internal migration - moving files between droplets over SSH/SCP

If you need to move a lot of files between DO server you can move these through SCP over the internal private Digital Ocean network.

NB both droplets need to be within the same region

To do this you need:

  1. enable private network for each droplet (if not done at creation, note the droplet needs to be off for this to be enabled once live)
  2. ensure that eth1 is enabled for both droplets if not already - see https://www.digitalocean.com/community/tutorials/how-to-enable-digitalocean-private-networking-on-existing-droplets
  3. scp files from the source server to the destination server are sent like:
@timvisee
timvisee / falsehoods-programming-time-list.md
Last active July 21, 2024 05:06
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@otikev
otikev / SillyMpesaMessageParser.java
Created January 24, 2018 18:30
A sample Parser for M-PESA SMSs. This works as of Jan 24th 2018. The format of the SMSs might/will change in future and this will not be relevant any more.
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 24 Jan, 2018
* Parses MPESA SMS String through simple String manipulation. And a tiny bit of regex :-D
*/
public class SillyMpesaMessageParser {
@simolus3
simolus3 / shopping_cart.dart
Last active November 21, 2023 12:27
Shopping carts in moor
import 'package:moor/moor.dart';
import 'package:moor/moor_vm.dart';
import 'package:rxdart/rxdart.dart';
part 'shopping_cart.g.dart';
class ShoppingCarts extends Table {
IntColumn get id => integer().autoIncrement()();
}
@themightychris
themightychris / config--env
Created October 22, 2019 20:40
Habitat plan.sh for Laravel application
#!{{pkgPathFor "core/bash"}}/bin/bash -e
if [ -f '{{pkg.svc_var_path}}/key' ]; then
APP_KEY="$(cat '{{pkg.svc_var_path}}/key')"
fi
APP_DEBUG='{{#if cfg.app.debug}}true{{/if}}'
APP_ENV='{{#if cfg.app.env}}{{cfg.app.env}}{{else}}production{{/if}}'
APP_URL='{{cfg.app.url}}'
@Braunson
Braunson / pivot-tables.md
Last active May 15, 2024 08:12
Laravel 8.x - Diving into Pivot Tables

Laravel 6 - Diving Into Pivot Tables

Pivot tables can be confusing and a little hard to wrap your head around at first. In this quick article we are going to dive into what a pivot table is, how to create one and finally how to use the pivot table. Let's dive in!

What is a pivot table?

A pivot table is used to connect relationships between two tables. Laravel provides a Many To Many relationship where you can use a pivot table.

@jorwan
jorwan / chunk_list_sample.dart
Last active May 28, 2023 15:43
Extension to chunk list
void main() => print(List.generate(10, (i) => i).chunk(3));
extension ListChunkerExtension on List {
List chunk(int chunkLength) {
if ((chunkLength ?? 0) <= 0 || (this ?? []).length == 0)
return this;
var chunks = [];
for (var i = 0; i < this.length; i += chunkLength) {
chunks.add(this.sublist(
i, i + chunkLength > this.length ? this.length : i + chunkLength));