Skip to content

Instantly share code, notes, and snippets.

View dreamingblackcat's full-sized avatar

Chan Myae San Hlaing dreamingblackcat

View GitHub Profile
@dreamingblackcat
dreamingblackcat / active_record_objects_autosave.md
Created July 7, 2021 03:38 — forked from demisx/active_record_objects_autosave.md
When Active Record Child Objects are Autosaved in Rails

belongs_to:

  1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

has_one:

  1. When you assign an object to a has_one association, that object is automatically saved (in order to update its foreign key).
  2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
  3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
  4. If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.

Types

A type is a collection of possible values. An integer can have values 0, 1, 2, 3, etc.; a boolean can have values true and false. We can imagine any type we like: for example, a HighFive type that allows the values "hi" or 5, but nothing else. It's not a string and it's not an integer; it's its own, separate type.

Type ဆိုသည်မှာဖြစ်နိုင်ခြေရှိသော တန်ဖိုးအစုအဝေးတစ်ခုဖြစ်သည်။ integer တစ်လုံးသည် ၀, ၁, ၂, ၃ အစရှိသည့်တန်ဖိုးများရှိနိုင်သည်။ Boolean တစ်လုံးသည် true နှင့် false ဟူသည့် တန်ဖိုးနှစ်မျိုးဖြစ်နိုင်သည်။ ကျွန်ုပ်တို့သည်ကျွန်ုပ်တို့ နှစ်သက်ရာ Type တစ်ခုကိုစိတ်ကူးကြည့်နိုင်သည်။ ဥပမာ တန်ဖိုး "hi" နှင့် 5 ဟူသည့်နှစ်မျိုးမှအပ အခြားတန်ဖိုးများကိုခွင့်မပြုသည့် Type တစ်ခုကိုစိတ်ကူးကြည့်မည်ဆိုပါစို့။ အဆိုပါ type သည် string တစ်ခုမဟုတ်သလို integer တစ်ခုလည်းမဟုတ်ပေ။၄င်းကိုယ်တိုင်က သီးခြား type တစ်ခုဖြစ်လေသည်။

Statically typed languages constrain variables' types: the programming language might know, for example, that x is an Integer.

<?
/////////////////////
// slack2html
// by @levelsio
/////////////////////
//
/////////////////////
// WHAT DOES THIS DO?
/////////////////////
//
@dreamingblackcat
dreamingblackcat / README.md
Last active September 16, 2015 14:11 — forked from mbostock/.block
Hexagon Mesh

Click and drag above to paint red hexagons. A black outline will appear around contiguous clusters of red hexagons. This outline is constructed using topojson.mesh, part of the TopoJSON client API. A filter is specified so that the mesh only contains boundaries that separate filled hexagons from empty hexagons.

The hexagon grid itself is represented as TopoJSON, but is constructed on-the-fly in the browser. Since TopoJSON requires quantized coordinates, the hexagon grid is represented as integers, with each hexagon of dimensions 3×2. Then a custom projection is used to transform these irregular integer hexagons to normal hexagons of the desired size.

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
source 'https://rubygems.org'
# default gems here
#---------------------------
# add paperclip and bootstrap
gem "paperclip", "~> 4.1"
gem 'bootstrap-sass', '~> 3.1.1'
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby