Skip to content

Instantly share code, notes, and snippets.

View stephan-buckmaster's full-sized avatar

Stephan Wehner stephan-buckmaster

View GitHub Profile
@stephan-buckmaster
stephan-buckmaster / sample-json.json
Created November 27, 2023 16:22
Sample JSON at a static URL
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
@stephan-buckmaster
stephan-buckmaster / compat-demo.sh
Created November 8, 2023 16:25
Demo how to setting env variable in shell, execute given commant
#!/usr/local/bin/bash
# Example usage -- compile https://gist.github.com/stephan-buckmaster/fd4662953d48737f7d592eeb772e76f1 under Linux system, obtain a.out
# Run $ compat-demo.sh a.out 'ABC DEF' 123
# a.out will have MY_LINUX_LIB_PATH set as follows
export MY_LINUX_LIB_PATH=/a/b/c/12/34
exec "$@" # Don't know how to do this in csh/tcsh -- allows treating arguments containing spaces as expected
#include "stdio.h"
int main(int argc, char **argv, char **envp)
{
printf("Environment:\n");
for (char **env = envp; *env != 0; env++)
{
char *thisEnv = *env;
printf("%s\n", thisEnv);
}
module GetConstNames
def my_const_names
Module.constants.select { |c| Module.const_get(c).object_id == self.object_id}
end
end
class ABC
include GetConstNames
end
im1 = imread('im1.png');
im2 = imread('im2.png');
imshow([im1 im2])
%%
im1 = im2double(im1);
im1_gray = rgb2gray(im1);
im2 = im2double(im2);
im2_gray = rgb2gray(im2);
%%
@stephan-buckmaster
stephan-buckmaster / bash-extensions.sh
Created December 28, 2018 07:55
Bash extensions history/git/misc.
# Couple of bash extensions. Place at end of ~/.bashrc
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history.
export HISTCONTROL=ignoredups
# ... and ignore same sucessive entries.
export HISTSIZE=5000
@stephan-buckmaster
stephan-buckmaster / gettext-extract.rb
Created September 27, 2018 21:34
Collapse po files
#!/usr/bin/ruby
# Collapses Gettext po files. for easy diff'ing
# Drops comments, and collapses quotes into one line.
# Example of what a po-file is: https://docs.transifex.com/formats/gettext
# Expanding the script by Raphaël Kolm at https://medium.com/@rkz_io/making-a-clutter-free-git-diff-on-gettext-translation-files-9c0c1bb1d8aa
# Sample output:
# 00001 msgid "is english def"
# 00001 msgstr "est anglais"
# 00002 msgid "good"
@stephan-buckmaster
stephan-buckmaster / pre-commit
Created June 28, 2018 16:50
Pre-commit hook to remind committer to run rake-assets-precompile
#!/bin/bash
#
# if changed assets are being committed, prompt the user to confirm
# they have precompiled assets.
if test $(git diff --cached --name-only | grep app/assets | wc -l) != 0
then
# grab user input
exec < /dev/tty
@stephan-buckmaster
stephan-buckmaster / mysql-drop-databases.rb
Created March 9, 2012 21:12
mysql: drop all databases
# a ruby script
get_database_list_command = "mysql -u root -p -e 'show databases' | grep -v Database | grep -v 'information' | grep -v 'mysql'"
database_names = ` #{get_database_list_command} `.split(/\n/)
drop_databases_sql_statements = database_names.collect { |db| "drop database if exists `#{db}`;" if db.length > 0}.compact.join(' ')
puts 'Executing drop commands:'
puts drop_databases_sql_statements
puts drop_databases_sql_statements.split(/;/).join(";\n")
<!DOCTYPE html>
<html data-nav-highlight-class-name="highlight-global-nav-home">
<head>
<title>Twitter</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8" />