Skip to content

Instantly share code, notes, and snippets.

View nestserau's full-sized avatar

Cheetah694 nestserau

  • Nederland, Randstad
  • 04:33 (UTC +01:00)
View GitHub Profile
@nestserau
nestserau / AtomicInteger.swift
Last active October 6, 2022 12:12
Atomic way to operate on integers in Swift. Inspired by Java's AtomicInteger
/// This is free and unencumbered software released into the public domain.
///
/// Anyone is free to copy, modify, publish, use, compile, sell, or
/// distribute this software, either in source code form or as a compiled
/// binary, for any purpose, commercial or non-commercial, and by any
/// means.
///
/// In jurisdictions that recognize copyright laws, the author or authors
/// of this software dedicate any and all copyright interest in the
/// software to the public domain. We make this dedication for the benefit
@nestserau
nestserau / move_and_rename.sh
Last active January 23, 2023 14:19
bash: Move and rename multiple files
find /path/to/directory -name "*.ext" -exec bash -c 'mv {} $(echo {} | sed -e "s/foo/bar/")' \;
@nestserau
nestserau / gist:f46a8abbc69a9697180d
Created June 25, 2015 07:19
Draw line in UIView
/* http://stackoverflow.com/questions/3128752/draw-line-in-uiview */
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0f);
@nestserau
nestserau / mysvn
Last active March 13, 2018 10:20
Subversion script to add all unadded and remove all unremoved files.
#!/bin/bash
usage()
{
printf "Supported commands:\n\tadd - adds all new files\n\tremove - removes all deleted files\n\tdiff - colorized diff\n"
exit 1
}
if [ "$#" -eq "0" ]; then usage; fi
if [ $1 == "add" ]; then
svn st | grep ^? | sed 's/^\? *//' | xargs -I% svn add %@
@nestserau
nestserau / gist:a8e3df58c13a9b92b185
Last active August 29, 2015 14:07
Backup APK content from the currently connected device
#!/bin/bash
output=~/data.ab
package=${1:-"com.my.package"}
openssl="/usr/local/opt/openssl/bin/"
export PATH=$openssl:$PATH
adb -d backup -f $output -noapk $package
pushd ~
dd if=$output bs=1 skip=24 | openssl zlib -d | tar -xvf -
rm $output
@nestserau
nestserau / gist:d97e5b3fffc95471ea4f
Last active August 29, 2015 14:06
Embed artwork with atomicparsley, oneliner, Mac OS X tested
for f in *.m4a; do atomicparsley "$f" --artwork folder.jpg; done; rm !(*temp*); for f in *.m4a; do g=${f//-temp*./.}; mv "$f" "$g"; done;
@nestserau
nestserau / gist:1f6e1621fdad199b5fce
Created May 1, 2014 11:40
View the change history of a file using Git versioning
I have got as far as:
git log -- [filename]
which shows me the commit history of the file, but how do I get at the content of each of the changes?
gitk [filename]
You can use
@nestserau
nestserau / gist:955e609f8c8175c5212d
Created April 29, 2014 20:41
How to search for a word in entire content of a directory in linux
If your grep supports the -r or -R option for recursive search, use it.
grep -r word .
Otherwise, use the -exec primary of find. This is the usual way of achieving the same effect as xargs, except without constraints on file names. Reasonably recent versions of find allow you to group several files in a single call to the auxiliary command. Passing /dev/null to grep ensures that it will show the file name in front of each match, even if it happens to be called on a single file.
find . -type f -exec grep word /dev/null {} +
Older versions of find (on older systems or OpenBSD, or reduced utilities such as BusyBox) can only call the auxiliary command on one file at a time.
@nestserau
nestserau / gist:11364907
Created April 28, 2014 08:02
Git commands aliases
function changes() {
if [ "$1" = "show" ]
then
git log -n 10 --no-merges
elif [ "$1" = "get" ]
then
git pull --rebase
elif [ "$1" = "post" ]
then
git push
@nestserau
nestserau / gist:11364748
Last active August 29, 2015 14:00
Launches an Android emulator with some predefined settings
pushd ~/.android/avd/$1.avd/
sed -i .bak 's/\(window.[xy] = \)-*[0-9]*/\10/g' emulator-user.ini
popd
pushd ~/android-sdks/tools/
if [ ! -z "$2" ]; then
emulator @$1 -scale $2
else
emulator @$1
fi
popd