Skip to content

Instantly share code, notes, and snippets.

View brendanashworth's full-sized avatar
🐦
bunting

Brendan Ashworth brendanashworth

🐦
bunting
View GitHub Profile
@brendanashworth
brendanashworth / gist:8534725
Last active January 3, 2016 23:19
Star out the last number set of an IP.
<?php
$ip = "10.0.11.145";
$array = explode(".", $ip);
$numbers = $array[0] . "." . $array[1] . "." . $array[2];
$numbers .= ".";
for($i = 0; $i < strlen($array[3]); $i++) {
@brendanashworth
brendanashworth / gist:3ff908eaf695f834fb60
Last active March 26, 2016 05:24
Every single *File that exists in these different language/libraries...
Podfile
Capfile
Gemfile
Gomfile
Makefile
Thorfile
Cakefile
Caskfile
Jakefile
Doxyfile
@brendanashworth
brendanashworth / main.rs
Last active March 8, 2024 10:50
Rust: reading lines from STDIN and printing them back to console
use std::io;
fn main() {
// Iterate over the lines in io::stdin()
for line in io::stdin().lines() {
// Now print the line (line.unwrap() first) via the println!() macro
println!("{}", line.unwrap());
}
}
@brendanashworth
brendanashworth / script.pl
Created June 17, 2014 01:10
Collatz conjecture for Perl
#!/usr/bin/perl
# This script finds the number of cycles necessary to get to 1 via the
# Collatz conjecture.
use strict;
use warnings;
unless (defined $ARGV[0]) {
print("Supply the integer as the first argument.");
exit;
}
@brendanashworth
brendanashworth / str_count.c
Last active August 29, 2015 14:02
Count occurrences of a string inside a string (C)
int str_count(char *string, char *delim) {
int count = 0;
int i;
for (i = 0; i < strlen(string); i++) {
if (strncmp(&string[i], delim, strlen(string))) {
count++;
}
}
return count;
@brendanashworth
brendanashworth / str_split.c
Last active August 29, 2015 14:02
Split a string by a delimiter into a string array
// NOTE: This gist requires https://gist.github.com/boboman13/956405a90345f3ce477c.
char **str_split(char *string, char *delim) {
uint8_t size = str_count(string, "") + 1, i;
char** split = malloc(size * sizeof(char*) );
for (i = 0; i < size; i++) {
if (i == 0)
split[i] = strtok(string, delim);
else
split[i] = strtok(NULL, delim);
@brendanashworth
brendanashworth / main.sql
Created June 27, 2014 01:45
MySQL command reference
# Select, insert, update, delete
SELECT * FROM `my_table` WHERE `my_field` = 'my_value';
INSERT INTO `my_table` (my_field, another_field) VALUES ('myFieldValue', 'AnotherFieldValue');
UPDATE `my_table` SET `my_field` = 'aNewValue';
DELETE FROM `my_table` WHERE `my_field` = 'a_special_value';
# Get the schema of sorts for a table
@brendanashworth
brendanashworth / main.md
Last active August 29, 2015 14:04
My favorite programming talks
@brendanashworth
brendanashworth / main.c
Created July 17, 2014 22:24
Basic example multithreading in C
#import <stdio.h>
#import <pthread.h>
void *threadFunction(void *arg) {
// To be executed when called...
}
int main(void) {
pthread_t *thread;
@brendanashworth
brendanashworth / main.sh
Created July 23, 2014 23:18
Create a .tar.gz archive from git, no external deps
#!/bin/bash
BRANCH=master
FORMAT=tar.gz
EXPORT_LOCATION=/tmp/backup.tar.gz
git archive $BRANCH -o $EXPORT_LOCATION --format $FORMAT