Skip to content

Instantly share code, notes, and snippets.

@Cloudef
Created January 25, 2012 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cloudef/1676321 to your computer and use it in GitHub Desktop.
Save Cloudef/1676321 to your computer and use it in GitHub Desktop.
Some system utilities
#!/bin/sh
# Workaround bug where nvidia-settings --load-config-only
# does not actually load any attributes.
#
# It might be related to values that have decimals such as
# RedBrightness=1.000000
# nvidia-settings will complain about (Trailing garbage), unless ran as root..
#
# However, running as root isn't really a nice thing, so this script just assign everything
# It will still give you complaints about (Trailing garbage), but at least other settings get applied.
#
# This will work as long the configuration file's attributes are in format
# HOSTNAME:DISPLAY/attribute=value
# eg. LINUX:0.0/CursorShadow=0
#
# or
#
# DISPLAY/attribute=value
# eg. 0/CursorShadow=0
#
# If nvidia ever changes their configuration, this script will break obviously :)
# Path to nvidia-settings configuration file
# or custom configuration
NVIDIA_SETTINGS_FILE="$HOME/.nvidia-settings-rc"
# Nvidia-settings utility
NVIDIA_SETTINGS_BINARY="nvidia-settings"
for value in $(egrep -v '^(#|$)' "$NVIDIA_SETTINGS_FILE" | grep '[0-9]/.*=');
do
value="$(echo "$value" | sed "s/$HOSTNAME//")"
"$NVIDIA_SETTINGS_BINARY" -a "$value"
done
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
/* TODO: read pipe? */
int main(int argc, char *argv[])
{
size_t i = 0, j = 0;
char s[LINE_MAX];
memset(s, 0, LINE_MAX);
/* join all strings */
i = 1; /* skip program, program */
for (; i != argc; ++i)
{
if (i != 1) strncat(s, " ", LINE_MAX);
strncat(s, argv[i], LINE_MAX);
}
/* count characters */
i = 0;
while (s[i]) {
if ((s[i] & 0xc0) != 0x80) j++;
i++;
}
/* print count */
printf("%llu\n", j);
return EXIT_SUCCESS;
}
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
/* TODO: read pipe? */
int main(int argc, char *argv[])
{
size_t i = 0, j = 0;
size_t trim = 0;
char s[LINE_MAX];
/* fail if no arguments */
if (argc < 3)
{
printf("usage: %s [string] [trim pos]\n", argv[0]);
return EXIT_SUCCESS;
}
/* get trim place */
trim = strtol(argv[2], (char **) NULL, 10);
/* count characters */
i = 0;
while (argv[1] && j != trim && i != LINE_MAX) {
if ((argv[1][i] & 0xc0) != 0x80) j++;
s[i] = argv[1][i];
i++;
}
if ((argv[1][i] & 0xc0) != 0x80)
{
/* ended on non multibyte */
}
else
{
/* ended at multibyte */
s[i] = argv[1][i]; ++i;
s[i] = argv[1][i]; ++i;
}
s[i] = '\0';
/* print count */
printf("%s\n", s);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment