Skip to content

Instantly share code, notes, and snippets.

View saagarjha's full-sized avatar

Saagar Jha saagarjha

View GitHub Profile
@steipete
steipete / openssl-build.h
Last active May 30, 2023 11:34
Updated script that builds OpenSSL with Bitcode enabled (tested with Xcode 7.0b3)
#!/bin/bash
# This script downlaods and builds the iOS and Mac openSSL libraries with Bitcode enabled
# Credits:
# https://github.com/st3fan/ios-openssl
# https://github.com/x2on/OpenSSL-for-iPhone/blob/master/build-libssl.sh
# Peter Steinberger, PSPDFKit GmbH, @steipete.
set -e
@saagarjha
saagarjha / .conkyrc
Last active December 1, 2016 06:30
A (modified) Google Now-inspired .conkyrc
# If you haven't already, download Conky Google Now from http://satya164.deviantart.com/art/Conky-Google-Now-366545753 and unzip it to your home folder; then copy this .conkyrc over the one you just extracted
# Requires lm-sensors and inxi (and conky) to be installed:
# sudo apt-get install lm-sensors inxi
# Adapted from these:
# http://satya164.deviantart.com/art/Conky-Google-Now-366545753
# https://gist.github.com/anonymous/6666594
# Conky Google Now style #
@saagarjha
saagarjha / GmailLabelArchive.gs
Created October 20, 2016 02:04
Google Apps Script to archive old emails in a label
function shouldStop(startTime) {
return new Date().getTime() - startTime.getTime() > 300000; // 5 minutes
}
function archive() {
var days = 7; // How old a message must be to be archived
var startTime = new Date();
var date = new Date();
date.setDate(date.getDate() - days);
var label = GmailApp.getUserLabelByName("[LABEL NAME]");
@saagarjha
saagarjha / git-ps1-status
Last active April 1, 2017 17:23
A Git summary for your Bash PS1 prompt
#!/usr/local/bin/bash
# Make sure this runs on a modern bash with support for ;;& in case
shopt -s extglob
# Make sure we're in a git directory
if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then
# Print a leading space to separate from the rest of the PS1
echo -n " "
# Check our status relative to upstream
@saagarjha
saagarjha / git-test-pr
Last active April 1, 2017 17:22
Try out Git pull requests locally
#!/bin/sh
if [ $# == 1 ]; then
git fetch origin pull/$1/head:pr-$1
git checkout pr-$1
elif [ $# == 2 ]; then
git fetch $1 pull/$2/head:pr-$2
git checkout pr-$2
else
echo "Usage: git test-pr [remote] pr#"
@saagarjha
saagarjha / xkcdSlackBot.gs
Last active April 11, 2018 06:31
Google Apps Script to post new xkcd comics to a Slack channel
function postUpdatedxkcdIfNecessary() {
var properties = PropertiesService.getUserProperties();
var latestComic = JSON.parse(UrlFetchApp.fetch("http://xkcd.com/info.0.json").getContentText());
if (latestComic["num"] > properties.getProperty("lastComic")) {
var title = latestComic["title"];
var imageURL = latestComic["img"];
var altText = latestComic["alt"];
var number = latestComic["num"];
@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active January 15, 2023 13:03
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
@saagarjha
saagarjha / cd.bash
Last active February 24, 2018 23:32
Bash function that provides a similar experience to zsh's cd history
cd() {
# Set the current directory to the 0th history item
cd_history[0]=$PWD
if [[ $1 == -h ]]; then
for i in ${!cd_history[@]}; do
echo $i: "${cd_history[$i]}"
done
return
elif [[ $1 =~ ^-[0-9]+ ]]; then
builtin cd "${cd_history[${1//-}]}" || # Remove the argument's dash
@saagarjha
saagarjha / pause4debug.c
Last active March 22, 2019 04:48
Simple dynamic library that, when injected, pauses programs during initialization
// Dynamic library that pauses a short lived program during launch so that a
// debugger can attach to it. To use it, compile it on macOS:
// clang -dynamiclib pause4debug.c -o pause4debug.dylib
// On Linux:
// gcc -shared -fPIC pause4debug.c -o pause4debug.so
// To use it, make the dynamic linker inject it using DYLD_INSERT_LIBRARIES or
// LD_PRELOAD, depending on your platform. On macOS:
// DYLD_INSERT_LIBRARIES=/path/to/pause4debug.dylib debugme
// On Linux,
// LD_PRELOAD=/path/to/pause4debug.so debugme
@fay59
fay59 / Quirks of C.md
Last active January 23, 2024 04:24
Quirks of C

Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.

There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
 int x;