Lebowtech Blog

Update PHP Time Zone for DST in Israel 5774

| Comments

So for what ever reason the Israeli government decided to change the law and extend Day Light Savings Time, שעון קיץ this year. The should just get rid of DST in my opinion, and I would be willing to bet that many people share that opinion.

Any way this change in DST means that may scripts are making wrong time calculations.

To fix this in PHP, you can use Athens for the time zone in Israel, but that is really hackish. The real fix is to install the new PECL timezone database.

No Talk Thursday

| Comments

So I have some suggestions to kind of remedy the situation. We’ve all heard of, like, casual Friday thing. How about no talk Thursdays? How about just one Thursday, once a month, and cut that day in half and just say the afternoon - I’ll make it really easy for you - so just silence. That’s it. And what you’ll find is that a tremendous amount of work actually gets done when no one talks to each other.

Living With a Dead Macbook Battery

| Comments

So I have been having a problem for the last few days. At night I would close my Macbook and put it to sleep and when I would open it again at work in the morning it would be shutdown and boot from scratch, no wake from sleep, and no hibernate. Anything I was working on yesterday was lost. Well not 100% lost because there is this annoying feature that after a crash, osx will open all the programs and windows that you last had open, but that is another story.

I realized that the problem is that my battery is dead, even though it lights up all the little green lights on the side.

My Battery Condition from the menu icon or from Energy Saver preference pane show ”Replace Now

Replace Now: The battery is functioning normally but holds significantly less charge than it did when it was new. You can continue to use the battery until you replace it without harming your computer.

And if I unplug my Macbook it shuts down almost immediately.

Set Macbook to hibernate instead of sleeping

So I can’t really get a new battery right now so I need a solution in the meantime.

I rarely work away from a power-supply so that isn’t an issue. What I need is to have my computer hibernate immediately when I close it.

This can be set up using sudo pmset hibernatemode 25.

From the man page:

hibernatemode = 25 (binary 0001 1001) is only settable via pmset. The system will store a copy of memory to persistent storage (the disk), and will remove power to memory. The system will restore from disk image. If you want “hibernation” - slower sleeps, slower wakes, and better battery life, you should use this setting.

See the man page for more info.

Converting Office From SVN to Git

| Comments

Looks like the day has finally come. At work we are going to try out git office wide on one of our largest projects. This is going to be a test to see if the less technically inclined people in the office can get used to it.

For now it looks like we are going to use git-svn so we can switch back to subversions if the changes don’t stick. I have already been using git-svn to work on almost all of our projects, it’s not perfect, but much better than working with svn straight.

Tools

I have tried a few different tools, but I always come back to the command line and magit on emacs, needless to say, those tools might not be the best for the general public, so we need to look into some nice gui interfaces.

So far we are trying out 2, Source Tree, and git tortoise.

Source Tree

Source tree is a nice looking cross platform application. I’ve used it a few times. It handles the usually stuff without much issue.

There is a mac and a windows version, so every one in the office can use the same app. The windows version doesn’t seem to support git-svn, so that is going to be a problem, ( the mac version supports it just fine).

It also seems to work well on repositiories that are located on network drives, not the case for other applications that I tried.

Git tortoise

This is supposed to be a clone of svn tortoise. Most of the window’s users here use svn tortoise so the interface should be familar, but there is no mac version.

It seems to support git-svn but it doesn’t ask for an authors file, so I don’t know how it plans to mach up users.

Emacs Function to Create Docblocks

| Comments

Here is a elisp function that I wrote to quickly add doc-blocks to code.

It changes the selected region to the first line of the doc-block so you can change it immediately.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(defun doc-block()
"Insert doc block"
(interactive)
(let 
    (
     (beg (point))
     (is-function (looking-at-p " *\\(\\(protected\\)\\|\\(public\\)\\|\\(protected\\)\\)? *function +\\([0-Z_-]+\\)(\\([^,)]+,?\\)*)" ))
     (is-class (looking-at-p "\s*class" ))
    )
    ( insert-string " /**
 * ")
    (if is-function (insert-string 
                     " new function
 *
 * @param string $param
 * @retrun null"))
   (if is-class (insert-string " new class
   * "))
      
    (insert-string "
 * @author ")
    (insert-string (user-real-login-name))
    (insert-string "
 */
")
    ;; re intent everything
    (forward-line 1)
    (indent-region beg (point))
    
    ;; select the description for easy edit
    (search-backward "/**")
    (forward-line 1)
    (search-forward "* ")
    (set-mark-command nil)
    (move-end-of-line nil)
    (setq deactivate-mark nil)
    )
)
(global-set-key "\C-cId" 'doc-block)

MySQL Split String Function

| Comments

MySQL does not include a function to split a delimited string. However, it’s very easy to create your own function.

SPLIT_STR FUNCTIONlink
1
2
3
4
5
6
7
8
9
CREATE FUNCTION SPLIT_STR(
  x VARCHAR(255),
  delim VARCHAR(12),
  pos INT
)
RETURNS VARCHAR(255)
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos),
       LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1),
       delim, '');

Convert Existing Git Repo to Svn

| Comments

Git is great for starting a project quickly but the office uses svn. Here is how I add my existing git repository to a new svn repo.

make svn from git
1
2
3
4
5
6
7
svn mkdir --parents  svn://repo/trunk svn://repo/branches svn://repo/tags
git svn clone -sA authors.file  svn://repo
cd repo
git checkout -b trunk trunk
git rebase master
git rebase remotes/trunk
git svn dcommit

First thing we do is make the new svn repository.

Then clone into our existing git repository, repo

Next we checkout the trunk, and rebase our existing work onto it.

Now we move master to point back to trunk, and push changed to svn.

Convert TimeZones in Mysql Preserving DST

| Comments

When converting time zones with MySql you should use the method CONVERT_TZ so that it will automatically take into account DST ( Daylight savings time / שעון קיץ )

convert date preserving timezone
1
SELECT CONVERT_TZ('2013-03-29 12:00','America/New_York','Asia/Jerusalem');

This will convert a date in New York to our local time.

If you do not use this method and just subtract 7 hours from the time, you will have errors when we switch to and from DST.