Skip to content

Instantly share code, notes, and snippets.

View SandroMachado's full-sized avatar

Sandro Machado SandroMachado

View GitHub Profile
@SandroMachado
SandroMachado / pi-reboot-on-network-failure
Created May 14, 2017 20:15
Script to reboot the raspberry pi if there is no network available
#!/bin/bash
while true
do
wget -q --tries=10 --timeout=20 --spider http://google.com
if [[ $? -eq 0 ]]; then
echo "Online"
else
echo "Offline"
echo raspberry | sudo -S sudo reboot
fi
@threepointone
threepointone / alternative.md
Last active July 31, 2022 17:46
list of things that don't do what they say they do

(also know as lies and/or alternative facts)

js

  • setImmediate - doesn't set anything immediately, waits for a tick before executing
  • setTimeout(fn, n) - never sets the timeout to exactly n
  • Math.random() - computers cannot generate random numbers
  • Promise - is a lie when rejected
  • Array.reduce - accumulates, does not reduce (via @sbmadhav)
let gifts = [ "partridge in a pear tree", "Two turtle doves", "Three French hens",
"Four calling birds", "Five golden rings", "Six geese a-laying",
"Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing",
"Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming" ]
let nth = [ "first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" ]
func gifts(for day: Int) -> String {
var result = "On the \(nth[day-1]) day of Christmas, my true love sent to me:\n"
import React from 'react';
import {
View,
Text,
} from 'react-native';
import { TextInputMask } from 'react-native-masked-text'
export default function maskedInputTemplate(locals) {
if (locals.hidden) {
return null;
@SandroMachado
SandroMachado / convert-to-webp.sh
Last active January 13, 2021 01:11
Script to convert all the `JPEG` images to the `WEBP` format in your Android project
#/bin/sh
# Inpiration: http://engineeringblog.yelp.com/2016/05/yelp-android-app-went-on-a-diet.html
# `-lossless` not used to give support for Android 4.0+
# Make sure cwebp is installed.
if ! type "cwebp" > /dev/null; then
echo "Please install cwebp to continue:"
echo "brew install webp"
exit 1
fi
@rock3r
rock3r / README.md
Last active January 27, 2024 14:51
A simple bash script to enable demo mode on a Marshmallow+ device via ADB (based on http://bit.ly/295BHLx)

Usage

$ demo on|off [hhmm]

Enable or disable the demo mode on a connected Android device or emulator. You can also pass in a custom value for the system clock in the HHMM format (only used when you use the on command).

⚠️ This script only works on *nix systems and has only been tested on macOS with Bash (but should be portable).

@ryanolsonk
ryanolsonk / top100.csv
Created January 11, 2016 04:01
Top 100 Apps
Rank Name Bundle ID Version Min iOS Version SDK Version Uses Swift Universal App VC Based Status Bar Management Xcode Version
1 Candy Crush com.midasplayer.apps.candycrushjellysaga1 1.6.5 6 iphoneos8.0 No Universal Global 610
2 Piano Tiles 2 com.cmplay.tiles2 1.1.7 7 iphoneos9.2 No Universal Global 720
3 Messenger com.facebook.Messenger 52 7 iphoneos9.1 No Universal VC Based 710
4 Instagram com.burbn.instagram 7.13.1 7 iphoneos9.1 No iPhone Only VC Based 710
5 YouTube com.google.ios.youtube 10.49.13 7 iphoneos8.4 No Universal Global 640
6 Snapchat com.toyopagroup.picaboo 9.21.1 7 iphoneos9.0 No iPhone Only Global 701
7 Meltdown com.robtop.geometrydashmeltdown 1 6 iphoneos9.1 No Universal Global 710
8 Facebook com.facebook.Facebook 46 7 iphoneos9.1 No Universal Global 710
9 Netflix com.netflix.Netflix 7.2.4 7 iphoneos9.0 No Universal VC Based 700
@jgilfelt
jgilfelt / CurlLoggingInterceptor.java
Created January 9, 2016 15:34
An OkHttp interceptor that logs requests as curl shell commands
/*
* Copyright (C) 2016 Jeff Gilfelt.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@plumhead
plumhead / StringSize.swift
Created September 15, 2015 13:34
String extension to find the layout size of a String with specified attributes.
extension String {
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect {
let storage = NSTextStorage(string: self)
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height))
let layout = NSLayoutManager()
layout.addTextContainer(container)
storage.addLayoutManager(layout)
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length))
container.lineFragmentPadding = 0.0
let _ = layout.glyphRangeForTextContainer(container)