Skip to content

Instantly share code, notes, and snippets.

View jesselawson's full-sized avatar
:shipit:

Jesse Lawson jesselawson

:shipit:
View GitHub Profile
@jesselawson
jesselawson / replace.c
Created July 25, 2015 14:50
Remove extra blanks from input
int c;
int lastc;
while((c=getchar()) != EOF) {
if(c == ' ') {
if(lastc == 1) {} else {putchar(c); lastc = 1; }
} else if (c != ' ') {
putchar(c);
lastc = 0;
} else {}
@jesselawson
jesselawson / remove-files-containing-string-in-filename.ps1
Created April 19, 2016 14:35
Powershell - Remove all files where filename contains string
$string = "MyString"
get-childitem | where-object {$_.Name -like "*$string*"} | foreach ($_) {remove-item $_.fullname}
@jesselawson
jesselawson / stage-files-from-index-file.ps1
Created February 2, 2017 19:19
We worked with a 3rd party vendor (ViaTRON) to scan a bunch of images. They created a text file with identifying information that included the location of the associated images, in incremental, integer form. This script was used to pull out the relevant fields and then stage the files to be uploaded to ImageNow.
# This file will read through the index files (*.txt) and
# copy/rename the files appropriately so that they're ready for upload to ImageNow
# Example index file:
# "SID","LAST NAME","FIRST NAME","DOB","DOCTYPE","IMAGE"
# "234234","Lastname","Firstname","1/15/1986","STUDENT APPLICATION","E:\APPLICATIONS\1.TIF"
# "345345","Johnson","Bob","8/25/1986","GRADE WAIVER","E:\APPLICATIONS\2.TIF"
# "456456","Doe","Jane","1/15/1986","STUDENT APPLICATION","E:\APPLICATIONS\3.TIF"
# Note that the index file is in CSV form.
@jesselawson
jesselawson / ExportSchema.ps1
Last active May 23, 2018 15:58 — forked from cheynewallace/ExportSchema.ps1
Export MSSQL schema with PowerShell. This script will export your schema definitions for tables, stored procs, triggers, functions and views to .sql files
# Usage: powershell ExportSchema.ps1 "SERVERNAME" "DATABASE" "C:\<YourOutputPath>"
# Start Script
Set-ExecutionPolicy RemoteSigned
# Set-ExecutionPolicy -ExecutionPolicy:Unrestricted -Scope:LocalMachine
function GenerateDBScript([string]$serverName, [string]$dbname, [string]$scriptpath)
{
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null

Keybase proof

I hereby claim:

  • I am jesselawson on github.
  • I am jesselawson (https://keybase.io/jesselawson) on keybase.
  • I have a public key ASBc9tUfZoktBJkb1UcDaFOiL8gmNK9ADR2jBlZjnT1CFgo

To claim this, I am signing this object:

@jesselawson
jesselawson / bad_string_literals.c
Created April 23, 2019 20:13
An example of how string literals persist in stack memory. This is NOT how you do dynamic strings!
#include <stdio.h>
#include <string.h>
int main(void) {
char* full_name = "Jesse Lawson";
char* ptr = full_name;
printf("newptr: %p\n", ptr);
full_name = "Jesse Happy Bubble Fun Club Lawson";
ptr = full_name;
printf("newptr: %p\n", ptr);
@jesselawson
jesselawson / dynamic_strings_example.c
Created April 24, 2019 15:50
An example of how you can use malloc(), realloc(), and free() to create dynamic strings.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void) {
// sizeof(char) is always 1, but we have it here
// for instructional purposes
char* full_name = malloc(sizeof(char)*strlen("Jesse Lawson")+1);
strcpy(full_name, "Jesse Lawson");
@jesselawson
jesselawson / main.rs
Last active October 22, 2019 00:01
Second Checkpoint, Getting Started with Rust by Building a Tiny Markdown Compiler (https://jesselawson.org/tutorials)
// Code for the Second Checkpoint
// Tutorial: https://jesselawson.org/rust/get-started-with-rust-by-building-a-tiny-markdown-compiler/
//
// The purpose of this checkpoint is to ensure that you have a complete copy
// of the code in the tutorial up to the checkpoint. I want you to tinker and
// explore, but to keep up with the rest of the tutorial, make sure your
// code matches this checkpoint.
fn get_version() -> u16 {
1000
@jesselawson
jesselawson / main.rs
Last active October 22, 2019 00:01
Third Checkpoint, Getting Started with Rust by Building a Tiny Markdown Compiler (https://jesselawson.org/tutorials)
// Code for the Third Checkpoint
// Tutorial: https://jesselawson.org/rust/get-started-with-rust-by-building-a-tiny-markdown-compiler/
//
// The purpose of this checkpoint is to ensure that you have a complete copy
// of the code in the tutorial up to the checkpoint. I want you to tinker and
// explore, but to keep up with the rest of the tutorial, make sure your
// code matches this checkpoint.
fn parse_markdown_file() {
// This will be created in Chapter 4
@jesselawson
jesselawson / main.rs
Last active October 22, 2019 00:00
Fourth Checkpoint, Getting Started with Rust by Building a Tiny Markdown Compiler (https://jesselawson.org/tutorials)
// Code for the Fourth Checkpoint
// Tutorial: https://jesselawson.org/rust/get-started-with-rust-by-building-a-tiny-markdown-compiler/
//
// The purpose of this checkpoint is to ensure that you have a complete copy
// of the code in the tutorial up to the checkpoint. I want you to tinker and
// explore, but to keep up with the rest of the tutorial, make sure your
// code matches this checkpoint.
fn parse_markdown_file(_file: &str) {
println!("[ INFO ] Trying to parse {}...", _file);