Skip to content

Instantly share code, notes, and snippets.

@joshuabradley012
joshuabradley012 / Object collisions with canvas
Last active June 3, 2025 18:30
An example of 2D collisions using JavaScript Canvas
class State {
constructor(display, actors) {
this.display = display;
this.actors = actors;
}
update(time) {
/**
* provide an update ID to let actors update other actors only once
@pixelrevision
pixelrevision / PascalJSONCodingTests.swift
Last active May 17, 2022 16:18
Pascal to Camel json coding
import XCTest
struct SampleCodable: Codable {
let sampleVariable1: String
let sampleVariable2: String
let cAPPEDVariable3: String
let sample: String
}
class PascalJSONCoding: XCTestCase {
@jongha
jongha / textview-to-drawable-on-android.kt
Created August 2, 2018 01:41
Textview to Drawable on Android
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val layout = inflater.inflate(R.layout.mixin_price_marker, null)
val text = layout.findViewById(R.id.text) as TextView?
text?.text = gasStationCard.price.toString()
layout.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED))
layout.layout(0, 0, layout.measuredWidth, layout.measuredHeight)
val bitmap = Bitmap.createBitmap(layout.measuredWidth, layout.measuredHeight, Bitmap.Config.ARGB_8888)
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
extension Notification {
struct UserInfoKey<ValueType>: Hashable {
let key: String
}
@magicien
magicien / Swift4_JSON_09.swift
Created October 3, 2017 00:54
How should I inherit Codable class?
import Foundation
let json = """
{
"a": 1,
"b": 2,
"c": 3
}
""".data(using: .utf8)!
@WorldDownTown
WorldDownTown / InsertRowsWithoutScrollingViewController.swift
Last active September 27, 2023 06:26
Insert rows in the top of UITableView without scrolling.
import UIKit
final class ViewController: UITableViewController {
private var names: [String] = (50...99).map { String($0) }
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
@paulocaldeira17
paulocaldeira17 / AppBarStateChangeListener.java
Last active August 22, 2024 06:23
Android AppBarLayout collapsed/expanded state listener
import android.support.design.widget.AppBarLayout;
/**
* App bar collapsing state
* @author Paulo Caldeira <paulo.caldeira@acin.pt>.
*/
public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener {
// State
public enum State {
EXPANDED,
import UIKit
class FloatingButtonController: UIViewController {
private(set) var button: UIButton!
required init?(coder aDecoder: NSCoder) {
fatalError()
}
@xcatliu
xcatliu / (已失效)中国区用户在开启 GitHub 两步验证中遇到的问题
Last active February 28, 2025 07:23
(已失效)中国区用户在开启 GitHub 两步验证中遇到的问题
2023.8.28
据多名网友回复,此方法已失效。
最新解决办法请参考此贴:[v2ex: 请问 github 的两步验证(two-factor authentication)大家是怎么做的?](https://www.v2ex.com/t/967533)
https://www.v2ex.com/t/967533
---
@calt
calt / Tabbar.Swift
Last active April 22, 2025 05:34
UITabBar with custom height in Swift, does not work for iOS 14 or later.
// Does not work on iOS 14.0 or later, keeping the gist just for reference.
extension UITabBar {
override open func sizeThatFits(size: CGSize) -> CGSize {
super.sizeThatFits(size)
var sizeThatFits = super.sizeThatFits(size)
sizeThatFits.height = 71
return sizeThatFits
}
}