Skip to content

Instantly share code, notes, and snippets.

View chayanforyou's full-sized avatar
🤖
Learning

Chayan Mistry chayanforyou

🤖
Learning
View GitHub Profile
@chayanforyou
chayanforyou / ideviceforward
Created October 27, 2024 14:02 — forked from gabrc52/ideviceforward
Forward iOS device from host to guest (OSX-KVM)
#!/bin/bash
# Debug
set -o xtrace
GUEST_IP=192.168.122.221
HOST_IP=192.168.122.1
# Wipe the current usbfluxd, usbmuxd, and socat:
sudo killall usbfluxd
@chayanforyou
chayanforyou / android_tools.sh
Created September 15, 2024 14:04 — forked from kriware/android_tools.sh
Auto install tools for android reversing in Ubuntu 20.04
#!/bin/bash
###################################################################
#Description : Script for install tools for android reversing
# Testing in Ubuntu 20.04
# Run as root
# Tools:
# - APKtool
# - Jadx
# - adb
@chayanforyou
chayanforyou / isolate_flutter.dart
Created March 4, 2024 04:53
Using an Isolate in Flutter
import 'dart:async';
import 'dart:isolate';
class CountdownTimer {
final receivePort = ReceivePort();
late Isolate _isolate;
void stop() {
receivePort.close();
_isolate.kill(priority: Isolate.immediate);

The technique I normally use is to prefix the data with a 4-byte rolling sequence number where the largest number represents the lastest / current value. In the case of storing 2 bytes of actual data that would give 6 bytes total and then I form into a circular queue arrangement so for 128 bytes of EEPROM it would contain 21 entries and increase endurance 21 times.

Then when booting the largest sequence number can be used to determine both the next sequence number to be used and the current tail of the queue. The following C pseudo-code demonstrates, this assumes that upon initial programming the EEPROM area has been erased to values of 0xFF so I ignore a sequence number of 0xFFFF:

struct
{
  uint32_t sequence_no;
  uint16_t my_data;
} QUEUE_ENTRY;
@chayanforyou
chayanforyou / Using .c files in Arduino.md
Created July 7, 2023 07:12
Arduino not working with ".c" file

The .ino files of Arduino sketches are compiled as C++ after a little bit of preprocessing. If you want to use C functions in C++, you need to wrap their declarations in:

extern "C" {}

There are a couple ways you can do this:

In the sketch:

@chayanforyou
chayanforyou / pic12f615_adc_interrupt.c
Created April 27, 2023 14:46 — forked from sapher/pic12f615_adc_interrupt.c
PIC12F615 ADC interrupt exemple
#include "xc.h"
#include "config.h"
#define _XTAL_FREQ 4000000
unsigned short pot = 0;
void interrupt isr() {
// Disable GIE (best practice?)
@chayanforyou
chayanforyou / MainActivity.java
Created October 9, 2022 09:52 — forked from blackcj/MainActivity.java
Design support library with CoordinatorLayout, SwipeRefreshLayout and RecyclerView.
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import com.blackcj.designsupportexample.adapters.RecyclerViewAdapter;
@chayanforyou
chayanforyou / AppbarSwipeRefreshLayout
Created October 9, 2022 09:36 — forked from ian-ellis/AppbarSwipeRefreshLayout
Fixing Up SwipeRefreshLayout to handle a collapsing toolbar
package au.com.qantas.qantas.common.presentation;
import android.content.Context;
import android.support.design.widget.AppBarLayout;
import android.util.AttributeSet;
import android.view.View;
import android.support.v4.widget.SwipeRefreshLayout;
public class AppbarSwipeRefreshLayout extends SwipeRefreshLayout implements
AppBarLayout.OnOffsetChangedListener {
@chayanforyou
chayanforyou / atmega8_timer0.c
Created October 1, 2022 02:53 — forked from mkleemann/atmega8_timer0.c
atmega8 timer0 - use overflow interrupt
// All values/comments are valid with ATmega8 running at Fosc = 4.000MHz
#include <avr/io.h>
#include <avr/interrupt.h>
// TIMER0 with prescaler clkI/O/1024
#define TIMER0_PRESCALER (1 << CS02) | (1 << CS00)
void main()