Showing posts with label Pemrograman. Show all posts
Showing posts with label Pemrograman. Show all posts

Saturday, August 16, 2025

Macro VBA script: Change format cross-reference with text pattern Example 6.X or 6.XX

Rule:
- Search only in text paragraphs.
- Match "Example 6.X" or "Example 6.XX".
- Change font → unbold + RGB blue.
- Skip if "Example 6.X" is the first word of the paragraph.

Sub ChangeCrossRefExampleFontColor()

    Dim para As Paragraph
    Dim rng As Range
    Dim firstWord As String
    
    For Each para In ActiveDocument.Paragraphs
        Set rng = para.Range
        
        ' Get the first word of the paragraph (without trailing space/punctuations)
        firstWord = Trim(Split(rng.Words(1).Text, " ")(0))
        
        With rng.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            
            ' Pattern: Example 6.X or Example 6.XX
            .Text = "Example 6.[0-9]{1,2}"
            .MatchWildcards = True
            
            ' Formatting
            .Replacement.Font.Bold = False
            .Replacement.Font.Color = RGB(0, 0, 255)
            
            ' Replace one by one inside this paragraph
            Do While .Execute(Replace:=wdReplaceOne)
                ' Check if found text = first word ? skip formatting
                If Trim(rng.Text) = firstWord Then
                    rng.Font.Bold = True ' revert any change
                    rng.Font.Color = wdColorAutomatic
                End If
                rng.Collapse wdCollapseEnd
            Loop
        End With
    Next para
    
    MsgBox "Formatting complete (excluding first word of each paragraph)!", vbInformation
End Sub

Monday, August 11, 2025

Macro VBA Script: Change font color of pattern-text 'Figure 6.XX' and 'Figure 6.X', where X is number, and located in text-paragraph

Sub ChangeCrossRefFigureFontColor()
    Dim doc As Document
    Dim para As Paragraph
    Dim paraRange As Range
    
    Set doc = ActiveDocument
    
    ' Loop through each paragraph in the document
    For Each para In doc.Paragraphs
        Set paraRange = para.Range
        
        ' Only process paragraphs outside of tables
        If paraRange.Information(wdWithInTable) = False Then
            With paraRange.Find
                .ClearFormatting
                .Text = "Figure 6\.[0-9]{1,2}"
                .MatchWildcards = True
                .Replacement.ClearFormatting
                .Replacement.Font.Color = RGB(0, 0, 230) ' Light blue
                
                ' Loop until all matches in paragraph are handled
                Do While .Execute(Replace:=wdReplaceOne) = True
                    paraRange.Font.Color = RGB(0, 0, 230)
                    ' Move start to after last found item
                    paraRange.Collapse Direction:=wdCollapseEnd
                Loop
            End With
        End If
    Next para
End Sub

Tuesday, August 5, 2025

Macro VBA Script: Add title text 'Figure 3.X' to all slides in PowerPoint

Sub AddFigureTitleToAllSlides()
    Dim sld As Slide
    Dim shp As Shape
    Dim slideIndex As Integer
    Dim titleSet As Boolean

    For Each sld In ActivePresentation.Slides
        slideIndex = sld.slideIndex
        titleSet = False

        ' Try to find and set the title placeholder if it exists
        For Each shp In sld.Shapes
            If shp.Type = msoPlaceholder Then
                If shp.PlaceholderFormat.Type = ppPlaceholderTitle Then
                    shp.TextFrame.TextRange.Text = "Figure 3." & slideIndex
                    titleSet = True
                    Exit For
                End If
            End If
        Next shp

        ' If no title placeholder, add a textbox at the top
        If Not titleSet Then
            Set shp = sld.Shapes.AddTextbox( _
                Orientation:=msoTextOrientationHorizontal, _
                Left:=50, Top:=20, Width:=600, Height:=50)
            With shp.TextFrame.TextRange
                .Text = "Figure " & slideIndex
                .Font.Size = 28
                .Font.Bold = True
            End With
        End If
    Next sld

    MsgBox "Titles 'Figure X' added to all slides.", vbInformation
End Sub

Wednesday, June 25, 2025

Macro VBA script: Change 1st column width for all table

 Sub SetFirstColumnWidthInPicas()

    Dim tbl As Table

    Dim r As Long

    Dim desiredWidthPicas As Single

    Dim desiredWidthPoints As Single


    ' Set desired width in picas

    desiredWidthPicas = 30 ' ? Change this as needed

    desiredWidthPoints = desiredWidthPicas * 12 ' Convert picas to points


    For Each tbl In ActiveDocument.Tables

        With tbl

            For r = 1 To .Rows.Count

                On Error Resume Next ' In case cell doesn't exist (e.g. merged)

                With .cell(r, 1)

                    .Width = desiredWidthPoints

                End With

                On Error GoTo 0

            Next r

        End With

    Next tbl


    MsgBox "First column width updated to " & desiredWidthPicas & " picas.", vbInformation

End Sub

Macro VBA script: Change Font name and size in the 2nd column for all table

 Sub ChangeFontInSecondColumn()

    Dim tbl As Table

    Dim r As Long, c As Long

    Dim cell As cell

    Dim targetCol As Long

    Dim rng As Range

    

    targetCol = 2 ' Second column


    For Each tbl In ActiveDocument.Tables

        With tbl

            For r = 1 To .Rows.Count

                On Error Resume Next ' In case cell(2) doesn't exist in a row

                Set cell = .cell(r, targetCol)

                If Not cell Is Nothing Then

                    Set rng = cell.Range

                    rng.End = rng.End - 1 ' Exclude end-of-cell marker

                    With rng.Font

                        .Name = "STIX Two Text"

                        .Size = 10

                    End With

                End If

                Set cell = Nothing

                Set rng = Nothing

                On Error GoTo 0

            Next r

        End With

    Next tbl


    MsgBox "Font updated in second column of all tables.", vbInformation

End Sub

Monday, November 25, 2024

Low pass filter waktu diskrit dan kontinu

Transfer function Laplace (s) untuk low pass filter

G(s) = K/(1+Tc.s)

dimana K adalah gain filter, Tc adalah konstanta waktu filter, s adalah variabel Laplace.

Persamaan beda untuk low pass filter diskrit

x[n+1] = (1-Ts/Tc).x[n] + K.(Ts/Tc).u[n]

y[n] = x[n]

dimana Ts adalah time sampling, Tc adalah konstanta waktu filter (cut-off), K adalah gain filter, dan u[n] adalah sinyal input filter.

Low-Pass Filter (Discrete or Continuous)

Monday, October 26, 2020

Script MATLAB: Plot spektrum frekuensi

fs = 1e3; % Sample frequency (Hz)

t = [0:1/fs:10]; % Time vector

x = 5*sin(2*pi*300.*t)+2*sin(2*pi*100.*t); % Signal

y = fft(x);

n = length(x);          % number of samples

f = (0:n-1)*(fs/n);     % frequency range

power = abs(y).^2/n;    % power of the DFT

plot(f,power)

xlabel('Frequency')

ylabel('Power')

Friday, March 30, 2018

When the tic-toc measurement is not reasonable?

Bismillah. In the Name of Allah, is the start of all things good. We too shall start with it.
(Said Nursi d. 1960)

I need to measure the computing time of my program for several matrix order. Tic-toc is perhaps very useful function provided in MATLAB for this task. But sometimes (not so much), this tic-toc gave me unreasonable time record for my program. Here for the example ...

Matrix Order |   1    |   2    |    3   | ...
Time         | 0.0122 | 0.0023 | 0.0015 | ...

It’s very weird situation. How can larger order matrix (2) takes faster time than (1). And it is also happened in other similar situations. I attempted any possible clue in getting rid of this problem: single thread computation, variable pre-declaration, running one-by-one instead of loop, etc. But nothing worked.

Sunday, February 11, 2018

Coding error detected: must be fixed by a programmer

Coding error detected, it must be fixed by a programmer: Failed to unserialise data from file. Either failed to read, or failed to write.

Problem:
There was a file locked by cache store system.

Solutions:
1. Execute script purgecaches to reset the cache system.
    php /moodle/admin/cli/purge_caches.php
2. Remove all files and directories unde directory /moodledata/cache

Finally, please don't edit core files to solve this problem. Think, in Moodle always was a alternative solutions.

https://coderwall.com/p/py-nba/moodle-easy-solution-to-failed-to-unserialise-data-from-file-either-failed-to-read-or-failed-to-write

Saturday, January 27, 2018

Efisien Membuat Matriks Identitas Ordo Puluhan/Ratusan Ribu

Mudah saja bila kita punya memory ram yang amat besar, atau ruang hardis yang longgar untuk virtual memory (swap/pagefile). Ordo 100rb saja, kita akan perlu memory 80 GB. Namun, untuk laptop rerata seperti punya saya, perlu ada akal2an untuk melakukan perhitungan matriks ordo puluhan/ratusan ribu. Alhamdulillah, MATLAB juga telah menyediakan olah matriks Sparse yang sangat tepat untuk kebutuhan terhadap matriks yang sebagian besar elemennya bernilai nol.

Tuesday, January 23, 2018

Efisiensi Iterasi Fungsi dengan Curve Fitting

Bismillah. Saya perlu membuat plot grafik dari suatu fungsi, f(t). Fungsinya sangat sederhana namun melibatkan matriks dengan ordo puluhan ribu. Sehingga, sekali iterasi bisa menanti 1500 detik. padahal saya perlu membuat plot kurva dalam 20 detik. Anggaplah iterasi dilakukan per detik, maka perlu 30000 detik, bisa meniren aku menanti.

Jadinya, saya buat iterasi tiap dua detik, jadi cuman 10 iterasi = 15000 detik. Ya... lumayan 50%. Namun kelemahannya, kurvanya nampak kaku, patah-patah, tidak smooth. Prof saya memberi intruksi agar coba menggunakan curve fitting atau smoothing di MATLAB. Saya googling, ternyata MATLAB menyediakannya, fungsi fit namanya.


z=fit(t,f,'splineinterp');
plot(z,'k',t,f,':');

Kodenya sederhana sekali dan perbandingan hasilnya, saya tampilkan pada gambar di atas. t adalah waktu, f adalah nilai fungsi tanpa fitting, dan z adalah hasil curve fitting, 'splineinterp' artinya saya menggunakan cubic interpolation. Alhamdulillah.

Saya menggunakan MATLAB 2008, very old. Saya kira versi 2017 jauh lebih magnificent.

Referensi

Friday, January 19, 2018

Efisiensi Memory dengan Sparse Matrix, Very Magnificent !

Bismillah. Masih seputar problematika komputasi matrix ordo tinggi yang sedang saya hadapi di MATLAB. Saya harus melakukan komputasi dengan matriks berordo 60rb x 60rb. Sepekan ini, saya stuck dibuatnya.

Pertama, saya menjumpai persoalan ketersediaan memory, solusi yang saya lakukan adalah menambah virtual memory hingga 30 GB. Persoalan memory selesai, saya jumpa persoalan komputasi. Beberapa kali setelah menanti luaama sekali, laptop macet, tidak respons sama sekali hingga harus di shutdown paksa.

Kedua, saya memperkecil pemakaian memory untuk matriks dengan menggunakan format 'single' hingga 50% efisiensinya. Namun ternyata persoalan komputasi masih belum teratasi.

Efisiensi Memory dengan Format Single untuk Matriks Ordo Tinggi

Bismillah. Ordo matriks terbesar yang saya libatkan adalah 60rb x 60rb. Secara default, MATLAB memerlukan memory sebanyak

60rb x 60rb x 8 bytes ~ 29 GB

Memory ram saya cuman 4 GB, virtual memory juga saya set hingga 50 GB. Komputasi menyita sebagian besar prosesor hingga laptop sering tidak responsif. Untuk mereduksi penggunaan memory, saya gunakan format bilangan single yang hanya memerlukan 4 bytes memory. Cara konversinya mudah sekali, misalnya

Tuesday, January 16, 2018

Menampilkan Lama Waktu Komputasi

Saat ini saya perlu mengukur lama waktu komputasi untuk membandingkan dua metode.

di MATLAB, cara untuk menampilkan waktu komputasi adalah dengan menambahkan 'tic' dan 'toc' di bagian awal dan akhir algoritma kita.

misalnya, seperti ini:

tic
Z1=kron(A,B);
Z2=kron(Z1,C);
toc

kron adalah operasi Kronecker product dari dua matriks. setelah dijalankan, maka akan tampil

Elapsed time 0.0014325 seconds

Ketika program dijalankan ulang, memang waktunya ndak sama persis, bergantung pada kesibukan prosesor, tapi relatif mirip2. Saya bisa gunakan tic toc ini untuk membandingkan dua metode, mana yang lebih efisien.

referensi: mathworks

Friday, August 11, 2017

WordPress Post Thumbnail not Shown via WhatsApp Share

Bismillah. I manage several websites using WordPress. klikmu.co is the most recent one. We use a theme named newspaper-X.

I faced a weird problem: When a post shared via Facebook, a featured image is shown and previewed by default. But when it is shared via WhatsApp, the image is not shown and replaced by a static web icon. Any different post I have shared via WhatsApp are always accompanied by the static web icon. It is really weird thing. This problem really stuck in my mind for two days.

Friday, April 28, 2017

Log Aktivitas untuk Blog @Moodle

Bismillah. Ada mahasiswa S3 yang disertasi tentang e-learning. Beliau request data log aktivitas untuk mata kuliahnya termasuk blog yang di dalamnya. Agak lama saya kesulitan menemukan cara mencari log untuk blog dan panduan dari google pun belum ada. Alhamdulillah, akhirnya ketemu solusinya. Query-nya saya tulis di sini siapa tahu ada yang memerlukan data yang sama.

SELECT p.courseid, p.module, ba.blogid, p.subject, ba.contextid, ls.userid, ls.action, ls.timecreated
FROM mdl_post p
JOIN mdl_blog_association ba ON p.id=ba.blogid
JOIN mdl_logstore_standard_log ls ON ba.contextid=ls.contextid
WHERE p.courseid IN (2208,2209,2210)

CATATAN
Isi blog tersimpan di tabel mdl_post, lognya tersimpan di mdl_logstore_standard_log, dan informasi tentang contextid sebagai perantara kedua tabel tersimpan di mdl_blog_association. Diujicoba di moodle 3.1.

Saturday, December 3, 2016

Dimana entri blog disimpan?

Ada mahasiswa S3 riset tentang elearning moodle dan request data log suatu matakuliah. Beliau lalu mengetahui bahwa entri blog tidak dimuat di mdl_logstore_standard_log. Lalu, setelah googling saya mendapati bahwa entri blog tersimpan di mdl_post.

SELECT * FROM `mdl_post` WHERE courseid = ‘xxxx’

Sekian. Mudah2an bermanfaat.

M. Nur Qomarudin

Monday, August 29, 2016

Membuat direktori writeable

Error message: Plugin files not writeable, Parent directory is not writeable
Eksekusi sebagai root:
chown -R www-data:www-data /var/www/html/
chmod -R u+w /var/www/html/
Selanjutnya, restart Apache2 (as root):
service apache2 restart
http://superuser.com/questions/927917/debian-permission-to-write-to-directories-and-files

Monday, June 27, 2016

Kode MATLAB Kalman Filter untuk Filter Sinyal

Bismillah. Seorang rekan yang sedang S3 di Australia berbagi persoalan tentang kalman filter diskrit. Dia sedang riset tentang estimasi profil jalan (road profile) dari hasil pengukuran akselerometer suspensi mobil dengan kalman filter diskrit. Dia juga memberi link berikut untuk kode kalman filter diskrit:

Wednesday, June 22, 2016

Cara Mengakses Data “Structure with time” di MATLAB

Ketika saya menyimpan data dari scope ke workspace dengan format Structure with time, bagaimana saya bisa mengakses atau memanfaatkannya?

Bismillah. Variabel yang tersimpan dengan format Structure with time di workspace tetap bisa saya manfaatkan baik untuk ditampilkan di command window maupun diplot grafiknya. Misal, saya simpan variabel ukur s1 dari scope dengan format tersebut, dimana kolom 1 memuat nilai kecepatan dan kolom 2 memuat nilai percepatan.