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 / 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);

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 / 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
@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 / 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 / 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 {}